时间:2021-07-01 10:21:17 帮助过:9人阅读
$conn=mysql_connect("localhost","root");mysql_select_db("xinshi");$sql="select image from photo order by id desc limit 6";$result=mysql_query($sql);//while ($row=mysql_fetch_array($result)){//print_r($row);}$row=mysql_fetch_array($result,MYSQL_NUM);print_r($row); mysql_close($conn);
不用while时,mysql_fetch_array 只是返回一条记录的数组,所以只有0有值
当用while时,while ($row=mysql_fetch_array($result)) 始终都在改变$row的值,$row本身的数组元素个数并没有改变。
楼上正解,LZ要数组的话可以这么写
include "mysqlconnect.php";
$sql ='select mealuid from mealtable';
$result=mysql_query($sql);
while ($row=mysql_fetch_array($result)) {
$arr[]=$row;
}
print_r($arr);
?>
不用while时,mysql_fetch_array 只是返回一条记录的数组,所以只有0有值
当用while时,while ($row=mysql_fetch_array($result)) 始终都在改变$row的值,$row本身的数组元素个数并没有改变。
那我如何取出这6个值?我要把这6个url连接到页面上的去显示出来
楼上正解,LZ要数组的话可以这么写
include "mysqlconnect.php";
$sql ='select mealuid from mealtable';
$result=mysql_query($sql);
while ($row=mysql_fetch_array($result)) {
$arr[]=$row;
}
print_r($arr);
?>
打印出来是这样的
Array (
[0] => Array ( [0] => upload/2013/05/08/14303.jpeg [image] => upload/2013/05/08/14303.jpeg )
[1] => Array ( [0] => upload/2013/05/03/14297 [image] => upload/2013/05/03/14297 )
[2] => Array ( [0] => upload/2013/05/03/14299.i [image] => upload/2013/05/03/14299.i )
[3] => Array ( [0] => upload/2013/05/03/14301.a [image] => upload/2013/05/03/14301.a )
[4] => Array ( [0] => upload/2013/05/03/137.image/jpeg [image] => upload/2013/05/03/137.image/jpeg )
[5] => Array ( [0] => upload/2013/05/03/14302image/jpeg [image] => upload/2013/05/03/14302image/jpeg )
)
这是怎么回事?这个结构什么意思?
while ($row=mysql_fetch_array($result)) { echo "\n";}
while ($row=mysql_fetch_array($result)) { echo "\n";}
while ($row=mysql_fetch_array($result,MYSQL_NUM)) {
$arr[]=$row;
}
print_r($arr);