2012-03-14 44 views
1

大家好我正在寫一個不返回任何東西給用戶的MySQL查詢。我究竟做錯了什麼?由於該分號MySQL數據庫查詢什麼也沒有返回

while($row = $res->fetchRow()); 

它不進入while循環的內容:

<?php 
require_once('MDB2.php'); 
include "mysql-connect.php"; 

// connect to database 

$dsn = "mysql://$username:[email protected]$host/$dbName"; 
$db =& MDB2::connect($dsn); 
if (PEAR::isError($db)) { 
    die($db->getMessage()); 
} 
$table_name="room"; 
$db->setFetchMode(MDB2_FETCHMODE_ASSOC); 

// list the rooms details 

$sql = "SELECT * FROM $table_name"; 
$res =& $db->query($sql); 
if (PEAR::isError($res)) { 
    die($res->getMessage()); 
} 

// display results but if no result has been found then we have to let the user know 

if($res->numRows() > 0) 
{ 
    echo "<table border=1> 
    <tr align='left'> 
    <th scope='col'>Name</th> 
    <th scope='col'>Weekend Price</th> 
    <th scope='col'>Weekday Price</th> 
    </tr>"; 
    while($row = $res->fetchRow()); 
    { 
     echo '<tr align="left">'; 
     echo "<td>" . $row['name'] . "</td>"; 
     echo "<td>&pound" . $row['weekend_price'] . "</td>"; 
     echo "<td>&pound" . $row['weekday_price'] . "</td>"; 
     echo "</tr>"; 
    } 
echo "</table>"; 
} 
else 
{ 
    echo "Nothing found."; 
} 
?> 
+0

你會得到錯誤嗎?啓用錯誤報告 – 2012-03-14 01:20:13

+0

這僅僅是我的眼睛還是你使用php4? – 2012-03-14 01:20:34

+0

沒有錯誤報告...但是沒有任何東西從SQL查詢返回,即表是空的。我也使用了正確的字段名稱。 – methuselah 2012-03-14 01:22:55

回答

3

從該行的末尾刪除分號。