Page 1 of 1

No results from mysql query.

Posted: Thu Jul 21, 2011 5:25 am
by Richard66
Hi all, I have the following code and the relevant database and tables set up on a localhost. Yet the query is returning nothing. No error message or results.

Code: Select all

<?php

$db_host = 'localhost';
$db_user = 'root';
$db_pass = 'root';
$db_database = 'bbg_db_2'; 

$dbc = mysql_connect($db_host,$db_user,$db_pass);
$sdb = mysql_select_db($db_database);

$query = "SELECT category_name, category_desc FROM categories";
$result = mysql_query($sdb, $dbc, $query)
or die (mysql_error($dbc));

while($row = mysql_fetch_array($result)) {
    
$catname = $row["category_name"];
$catdesc = $row["category_desc"];
    
echo "<li>$catname</br><span>$catdesc</span></a></li>";

}

?>
If anyone has any ideas why this is not working I would be very grateful. Many thanks in advance.

Re: No results from mysql query.

Posted: Thu Jul 21, 2011 9:24 am
by social_experiment
What results do you receive if you modify the $result variable like the example below

Code: Select all

<?php
$result = mysql_query($sdb, $dbc, $query);
# try
$result = mysql_query($query, $dbc);
?>

Re: No results from mysql query.

Posted: Fri Jul 22, 2011 4:47 am
by Richard66
Your spot on. Thankyou so much. I was storing the result from the mysql_select_db in the wrong place. I don't need to store it and also as you have shown the $query should come before the database connection in $result.