test.php  为什么取不到值?<?php
mysql_connect("localhost","root","123456");
mysql_select_db("test");$arr=array("1","2","3","5","10","6","9");
$query=mysql_query("select * from aaa where id in($arr)");//in("数组"),明了的意思---取得id=1、2、3...的信息
while($result=mysql_fetch_array($query)){
echo $result[0]."<br>";
echo $result[1].""<br>;
}
?>错误信息:mysql_fetch_array(): supplied argument is not a valid MySQL result resource .......

解决方案 »

  1.   


    $query=mysql_query("select * from aaa where id in('$arr')");
      

  2.   

    你真有才,直接把数组放到字符串里去
    给你提示下,用join函数
      

  3.   

    LZ还up什么,赶紧去复习sql的in语句,你把php数组直接扔sql语句里,php和mysql虽然很熟悉,但不是一个娘胎出来的。
      

  4.   


    烦啊烦,不会出现错误了,只是echo的时候没东西...
      

  5.   


    $str = "1,2,3,5";
    $query=mysql_query("select * from aaa where id in($str)");
    $arr=array("1","2","3","5","10","6","9");
    $str = implode(',', $arr);
    $query=mysql_query("select * from aaa where id in($str)");
      

  6.   


    <?php
    mysql_connect("localhost","root","");
    mysql_select_db("test");$arr=array("1","2","3","5","10","6","9");
    $sql = "select * from s where id in(".join(',',$arr).")";
    $query=mysql_query($sql);//in("数组"),明了的意思---取得id=1、2、3...的信息
    //echo $sql;
    while($result=mysql_fetch_array($query)){
    echo $result[0]."&nbsp&nbsp";
    echo $result[1]."<br>";
    }
    ?>上面的可以运行。
      

  7.   

    没什么好办法,除非一条一体的查询。for($i=0;$i<count($arr);$i++){
      mysql_query("select * from aaa where id = $arr[$i]");
      ....................
    }
      

  8.   

    order by find_in_set...select * from table where id in(1,2,3,4,10,6,9) order by find_in_set(id,'1,2,3,4,10,6,9') asc