1

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>&pound" . $row['weekend_price'] . "</td>";
        echo "<td>&pound" . $row['weekday_price'] . "</td>";
        echo "</tr>";
    }
echo "</table>";
}
else
{
    echo "Nothing found.";
}
?>
7
  • are you getting errors? enable error reporting Commented Mar 14, 2012 at 1:20
  • Is it just my eyes or u r using php4? Commented Mar 14, 2012 at 1:20
  • No error reports... but nothing is being returned from the SQL query i.e. the table is empty. I have used the correct field names as well. Commented Mar 14, 2012 at 1:22
  • @ItayMoav what's wrong with PHP4? Commented Mar 14, 2012 at 1:23
  • 2
    Besides the fact it is VERY old, not maintained and who knows what extension version you use, which might be full of bugs...nothing wrong. Commented Mar 14, 2012 at 1:27

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.