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 .......
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 .......
$query=mysql_query("select * from aaa where id in('$arr')");
给你提示下,用join函数
烦啊烦,不会出现错误了,只是echo的时候没东西...
$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)");
<?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]."  ";
echo $result[1]."<br>";
}
?>上面的可以运行。
mysql_query("select * from aaa where id = $arr[$i]");
....................
}