Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php的Mysql选择查询_Php_Mysql_Select - Fatal编程技术网

使用php的Mysql选择查询

使用php的Mysql选择查询,php,mysql,select,Php,Mysql,Select,我正在尝试从表'student'中获取所有行。 但它只返回数组中的第一行。 如何获取数组中的所有行 我的代码是- <?php // con ref $dbCon = mysql_connect("localhost","root","") or die("connection problem".mysql_error()); // db con mysql_select_db("mysql_db",$dbCon); $sql = "select * from stude

我正在尝试从表'student'中获取所有行。 但它只返回数组中的第一行。 如何获取数组中的所有行

我的代码是-

<?php
  // con ref
  $dbCon = mysql_connect("localhost","root","") or die("connection problem".mysql_error());
  // db con
  mysql_select_db("mysql_db",$dbCon);
  $sql = "select * from student ";
  $data = mysql_query($sql);
  $row = mysql_fetch_array($data);
  print_r($row);
?>

您需要循环查看结果

while( $row = mysql_fetch_array($data) ) {
    print_r($row);
}

一个如何迭代结果的示例

根据以下文件:

获取结果行作为关联数组、数字数组或两者

注意a结果

您将希望在所有行中循环,例如:

while($row = mysql_fetch_array($data)) {
   // Use $row here..
}

另外,您应该注意到,
mysql.*
函数的使用已被弃用。看到那个红色的大盒子了吗。考虑使用或代替。

停止使用MQLL1的第一个停止。 第二条读到这个人:


它清楚地表明函数
mysql\u fetch\u array
返回一行

google是您的朋友。“获取数组中的所有行”=许多结果:在新代码中。它们不再得到维护,而是在使用。看到红色的盒子了吗?相反,请学习准备好的语句,并使用or。请不要鼓励在PHP MYSqL-library的邪恶中使用noobie
while($row = mysql_fetch_array($data)) {
   // Use $row here..
}