开发者

PHP SQL only returning 1 response instead of multiple

Here's the PHP and I'll explain as I go

$query = "SELECT id, attendees FROM events WHERE creator = '63' AND attendees LIKE '%74%'";

$result = mysqli_query($dbc,$query);

$uid_events = mysqli_fetch_array($result,MYSQLI_ASSOC);

echo $_GET['callback'] . '("' . stripslashes(json_encode($uid_events)) . '");';

It's a jquery JSONP request and I'm trying to retrieve 2 records.

When I test this exact same query directly in my database I get these 2 records:

34acb43ccc4c34b911ba8b7d850a846b63 - 63,1,74     
09fa87b2ed809d674开发者_如何学JAVA1c43dd669c83e1a63 - 63,74

But the PHP echoes out:

({"id":"34acb43ccc4c34b911ba8b7d850a846b63","attendees":"63,1,74"}");

Any help would be appreciated.


try this:

while ($uid_events = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
   echo $_GET['callback'] . '("' . stripslashes(json_encode($uid_events)) . '");';
}


The function mysqli_fetch_array fetches only one row (or returns FALSE if there are no more rows). If you want to read all rows you should run this statement in a loop, until it returns FALSE.


mysqli_featch_array() returns a single row, then advances the cursor to the next row. To get all rows, you need to call it in a loop.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜