while($row=mysql_fetch_assoc($result)):
求詳細解釋
回複討論(解決方案)
當執行返回不是一個空結果的時候一直迴圈.
極少用while 總覺得不好控制
1.while(condition) {dosomething();} condition = true時dosomething()一直執行,否則跳出迴圈.
2.$row=mysql_fetch_assoc($result) 賦值,沒有更多行時返回false
綜上,在資料庫沒有資料之前會一直執行dosomething();的內容.
另外,貌似現在php已經不推薦用mysql_fetch_assoc()這個函數了可以考慮試用mysqli或者pdo替換
1.while(condition) {dosomething();} condition = true時dosomething()一直執行,否則跳出迴圈.
2.$row=mysql_fetch_assoc($result) 賦值,沒有更多行時返回false
綜上,在資料庫沒有資料之前會一直執行dosomething();的內容.
另外,貌似現在php已經不推薦用mysql_fetch_assoc()這個函數了可以考慮試用mysqli或者pdo替換
mysql_fetch_assoc 這個函數是什麼意思?
1.while(condition) {dosomething();} condition = true時dosomething()一直執行,否則跳出迴圈.
2.$row=mysql_fetch_assoc($result) 賦值,沒有更多行時返回false
綜上,在資料庫沒有資料之前會一直執行dosomething();的內容.
另外,貌似現在php已經不推薦用mysql_fetch_assoc()這個函數了可以考慮試用mysqli或者pdo替換
mysql_fetch_assoc 這個函數是什麼意思?
將結果行以關聯陣列形式返回
mysql_fetch_assoc 這個函數是什麼意思?
官方手冊是最好的教程。
http://php.net/manual/zh/function.mysql-fetch-assoc.php