I have a simple database like this :
我有一个像这样的简单数据库:
Name id
-----------
music 1
sport 2
theatre 3
I just want to display
我只是想展示
music
theatre
I call a function with the ids and want to show name corresponding, my query looks like this, but nothing happen
我使用id调用一个函数,并希望显示相应的名称,我的查询看起来像这样,但没有任何反应
$array = array(1,3);
$id = implode(',', $array);
$result = doQuery("SELECT Name
FROM categories c
WHERE c.id IN '" . $id. "'
");
if(hasRows($result)){
while($row = mysql_fetch_row($result)){
echo $row[0];
}
}
2 个解决方案
#1
1
When you are using IN, you must place the conditions in parenthesis but in you case you are not using them so try something like this:
当您使用IN时,必须将条件放在括号中,但在您没有使用它们的情况下,请尝试以下方法:
$array = array(1,3);
$id = implode(',', $array);
$result = doQuery("SELECT Name
FROM categories c
WHERE c.id IN (" . $id. ")
");
if(hasRows($result)){
while($row = mysql_fetch_row($result)){
echo $row[0];
}
}
#2
0
I suspect you need your IN wrapped in ( ) not ' '.
我怀疑你需要你的IN包裹在()不是''。
$result = doQuery("SELECT Name
FROM categories c
WHERE c.id IN (" . $id. ")
");
#1
1
When you are using IN, you must place the conditions in parenthesis but in you case you are not using them so try something like this:
当您使用IN时,必须将条件放在括号中,但在您没有使用它们的情况下,请尝试以下方法:
$array = array(1,3);
$id = implode(',', $array);
$result = doQuery("SELECT Name
FROM categories c
WHERE c.id IN (" . $id. ")
");
if(hasRows($result)){
while($row = mysql_fetch_row($result)){
echo $row[0];
}
}
#2
0
I suspect you need your IN wrapped in ( ) not ' '.
我怀疑你需要你的IN包裹在()不是''。
$result = doQuery("SELECT Name
FROM categories c
WHERE c.id IN (" . $id. ")
");