我的代码是 -
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'moviefone';
$con = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname, $con);
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$data = mysql_query("SELECT * FROM new_hindi") or die(mysql_error());
$info=NULL;
while ($row = mysql_fetch_array($data)){
$info=$row;
}
?>
我的问题是循环只显示“new_hindi”表中的最后一条记录。
答案 0 :(得分:0)
每次迭代时,都会覆盖$info
变量。您必须向$info
数组添加行。
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'moviefone';
$con = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname, $con);
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$data = mysql_query("SELECT * FROM new_hindi") or die(mysql_error());
$info=array();
while ($row = mysql_fetch_array($data)){
$info[]=$row;
}
?>