2012-03-14 9 views
1

皆さん、私は現在、ユーザに何も返さないMySQLクエリを作成しています。私は間違って何をしていますか?MySQL DBクエリは何も返しません

<?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

エラーが報告されますか?エラー報告を有効にする –

+0

php4を使用しているのは私の目ですか? –

+0

エラーレポートはありませんが、SQLクエリから何も返されません。つまり、テーブルは空です。私も正しいフィールド名を使用しています。 – methuselah

答えて

3

は、この行の末尾からセミコロンを削除します。それは、whileループの内容を入力することではないです

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

によりその半結腸に。

関連する問題