查询未在函数中返回正确的结果
以下函数设置为:
- 从我的数据库收集
user_id
,如下面WHERESubscriber = '$user'
所示。然后: - 返回
user_id
可能的多个值。
但是,当我尝试使用此函数时,它只收集了一个数组,其中包含键 0
和值 user_id
。出于明显的原因,我希望数组包含数据库中 user_id
列中带有键 user_id
的数值。
function get_subscribitions($user)
{
$user = mysql_real_escape_string ($user);
$sql = "SELECT 'user_id' FROM `subscribe` WHERE subscriber = '$user'";
$result = mysql_query($sql);
$rows = array();
while ($row = mysql_fetch_assoc($result)) {
$rows[] = $row;
}
mysql_free_result($result);
return $rows;
}
谁能指出我在哪里犯了导致这些相关问题的错误?
任何帮助表示感谢,预先感谢您!
The following function is set up to:
- Collect the
user_id
from my database, as you can see belowWHERE subscriber = '$user'
. And then: - return the possible multiple values that
user_id
are.
However, when I've tried to use this function, it has only collected an array, with the key 0
, and value user_id
. For apparent reasons I want the array to contain the numerical value that is in the user_id
column in my database with the key user_id
.
function get_subscribitions($user)
{
$user = mysql_real_escape_string ($user);
$sql = "SELECT 'user_id' FROM `subscribe` WHERE subscriber = '$user'";
$result = mysql_query($sql);
$rows = array();
while ($row = mysql_fetch_assoc($result)) {
$rows[] = $row;
}
mysql_free_result($result);
return $rows;
}
Can anyone please pinpoint where I'm making the error leading to these related problems?
Any help appreciated, thank you in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
应该是:
查询中存在不必要的引号,并且您没有正确读取 $row 数组
It should be:
There were unnecessary quotes in the query and you were not reading the $row array properly
尝试改为
注意
user_id
周围缺少单引号Try instead
Notice the single quotes missing from around
user_id