Reputation: 13216
Hi everyone I'm currently writing a MySQL query that doesn't return anything to the user. What am I doing wrong?
<?php
require_once('MDB2.php');
include "mysql-connect.php";
// connect to database
$dsn = "mysql://$username:$password@$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>£" . $row['weekend_price'] . "</td>";
echo "<td>£" . $row['weekday_price'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
else
{
echo "Nothing found.";
}
?>
Upvotes: 1
Views: 361
Reputation: 2228
Remove the semi-colon from the end of this line:
while($row = $res->fetchRow());
It's not entering the contents of the while loop due to that semi-colon.
Upvotes: 3