-1

我有以下查询:

$sql_select_todo = 
                  "SELECT * FROM 
                               to_do_items 
                            WHERE
                               id_project = ".$_SESSION['selected_projectId']."'
                            AND 
                               id IN ('".$alleTaken."')";

$query_select_todo = mysql_query($sql_select_todo) or die(mysql_error());

while($fetch_todo = mysql_fetch_assoc($query_select_todo))  {

    echo $fetch_todo['name'];
}

当我回显查询时,我得到了这个:

SELECT * FROM to_do_items WHERE id_project = '7401' AND id IN ('10193,12848') 

但是输出只会返回一个名字($fetch_todo['name'])

但是有 2 个 id,所以我应该得到 2 个名字。我在这里做错了什么?

4

1 回答 1

0

删除 IN 查询中的单引号

改变

$sql_select_todo = 
                  "SELECT * FROM 
                               to_do_items 
                            WHERE
                               id_project = ".$_SESSION['selected_projectId']."'
                            AND 
                               id IN ('".$alleTaken."')";

$sql_select_todo = 
                  "SELECT * FROM 
                               to_do_items 
                            WHERE
                               id_project = ".$_SESSION['selected_projectId']."'
                            AND 
                               id IN (".$alleTaken.")";
于 2013-10-13T09:26:14.353 回答