我遇到了最簡單的一段代碼的麻煩。出於某種原因,以下代碼僅檢索數據庫中的第一行。我正在嘗試一段時間循環,它只是不適合我。這裏是我的代碼:幫助PHP雖然循環
<?php
//Connect to the database
require_once('mysql_connect.php') ;
$query = "SELECT * FROM past_due_students WHERE charged_today = 'No' ORDER BY past_due_id" ;
$result = mysqli_query($dbc, $query) ;
$number_of_students = mysqli_num_rows($result)
if ($number_of_students >= 1) {
//Loop through the entire table
while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {
$student_id = $row['student_id'] ;
$number_of_declines = $row['number_of_declines'] - 1;
//Update the number of declines
$query = "UPDATE past_due_students SET number_of_declines = $number_of_declines WHERE student_id = $student_id" ;
$result = mysqli_query($dbc, $query) ;
$number = mysqli_affected_rows($dbc) ;
if ($number == 1) {
echo '<p><b>The number of declines has been successfully updated.</b></p>' ;
} else {
echo $query ;
}
}//END while loop
}//END if ($number_of_students >= 1) {
?>
它只抓取第一行,沒有其他行。任何幫助是極大的讚賞。
'$ number_of_students = mysqli_num_rows($ result)'後缺少';'。除此之外:var_dump($ number_of_students);'給了什麼? – 2011-06-03 15:54:17