PHP SQL 仅返回 1 个响应而不是多个
这是 PHP,我将解释
$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)) . '");';
它是一个 jquery JSONP 请求,我正在尝试检索 2 条记录。
当我直接在数据库中测试这个完全相同的查询时,我得到这两条记录:
34acb43ccc4c34b911ba8b7d850a846b63 - 63,1,74
09fa87b2ed809d6741c43dd669c83e1a63 - 63,74
但 PHP 回显:
({"id":"34acb43ccc4c34b911ba8b7d850a846b63","attendees":"63,1,74"}");
任何帮助将不胜感激。
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
09fa87b2ed809d6741c43dd669c83e1a63 - 63,74
But the PHP echoes out:
({"id":"34acb43ccc4c34b911ba8b7d850a846b63","attendees":"63,1,74"}");
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个:
try this:
函数
mysqli_fetch_array
仅获取一个行(如果没有更多行则返回 FALSE)。如果您想读取所有行,您应该循环运行此语句,直到返回 FALSE。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()
返回单个行,然后将光标前进到下一行。要获取所有行,您需要循环调用它。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.