php mysql_fetch_object无休止的转动

时间:2018-06-01 06:36:41

标签: javascript php html ajax mysqli

<? 
$DBAlanadi = "SELECT * FROM Alanadi";
$ACAlanadi = mysql_query($DBAlanadi);
$TotalAlanadi = mysql_num_rows($ACAlanadi);
$Alanadi = mysql_fetch_object($ACAlanadi);

if($TotalAlanadi!=0): 
     while( $Fiyat=$Alanadi ): 
         echo '<a>'.$Fiyat->fiyat.'</a>'; 
     endwhile; 
 endif;
 mysqli_free_result($Alanadi); ?>

第1行只是无休止地转动

我想要 40 TL 35 TL 50 TL

1 个答案:

答案 0 :(得分:0)

每次循环都需要调用mysql_fetch_object()。否则你只是一遍又一遍地处理第一行。

<? 
$DBAlanadi = "SELECT * FROM Alanadi";
$ACAlanadi = mysql_query($DBAlanadi);
$TotalAlanadi = mysql_num_rows($ACAlanadi);

if($TotalAlanadi!=0): 
     while( $Fiyat= mysql_fetch_object($ACAlanadi) ): 
         echo '<a>'.$Fiyat->fiyat.'</a>'; 
     endwhile; 
 endif;
 mysql_free_result($Alanadi); 
?>

BTW,mysql扩展已被弃用多年,并且已从当前版本的PHP中完全删除。您应该尽快转换为mysqliPDO

如果结果来自mysqli_free_result,则无法致电mysql,您必须使用mysql_free_result

请参阅Can I mix MySQL APIs in PHP?