Alright, so I have a php that responds to a GET HTTP request; this php script calls the database, and retrieves a set of rows.
$results = $db->pdoquery("SELECT * FROM posts JOIN users ON posts.user_id=users.id ORDER BY posts.cre DESC LIMIT 4");
$json = json_encode($results);
echo $json;
Now when I use backbonejs ‘.fetch’ command, it only returns 1 the first record, as opposed to the four.
If I change the php script I get all four, but I have to lose my JOIN
$results = $db->pdoquery("SELECT * FROM posts ORDER BY posts.cre DESC LIMIT 4");
$json = json_encode($results);
echo $json;
Can anyone explain what I’m doing wrong?
UPDATE :
The JSON that the php page prints
[{"id":"7","post_name":"title","pretty_url":"link1","preface":"a preface 7","body_text":"a body","feat":"0","img":"\/img\/logo.png","cre":"2012-07-22","modi":"2012-07-18","user_id":"2"},{"id":"6","post_name":"title","pretty_url":"link","preface":"a preface 6","body_text":"a body1","feat":"0","img":"\/img\/logo.png","cre":"2012-07-21","modi":"2012-07-18","user_id":"2"},{"id":"5","post_name":"TestTitle 1","pretty_url":"testlink4","preface":"a preface 5","body_text":"a body 2","feat":"0","img":"\/img\/logo.png","cre":"2012-07-20","modi":"2012-07-16","user_id":"2"},{"id":"4","post_name":"TestTitle 1","pretty_url":"testlink3","preface":"a preface 4","body_text":"a body 3","feat":"0","img":"\/img\/logo.png","cre":"2012-07-19","modi":"2012-07-16","user_id":"2"}]
I found the problem.
Posts and Users has columns with identical names, mainly ‘id’, and since these four post records has the same user_id, the ‘id’ column was then set the same value.
Backbone must have something built in that skips over what it considers to be identical records or something of the sort. Simply describing what I needed in more detail fixed the issue.
Regardless the code that fixed it is below
Thanks to everyone that helped though.