0

我的代码是 -

$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”表中的最后一条记录。

4

1 回答 1

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;
}

?>
于 2013-11-10T19:47:21.610 回答