Richard Bell
Richard Bell

Reputation: 405

Problem displaying query results

I have a MySQL table set up using phpMyAdmin which you can view in the images below:

Table Structure

And here is the populated table:

Categories

The problem I have is when I issue the following query, no results are returned. I am struggling to work out why.

<?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>";
}
?>

When I issue this query I get no error messages and no results displayed. All I am trying to do is get a list of all these categories with their descriptions. Any Ideas?

Upvotes: 1

Views: 103

Answers (1)

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385405

Your parameters to mysql_query are wrong. The results of mysql_select_db do not belong there, and the query should be the first parameter.

Check out the documentation for every function you use.

Upvotes: 1

Related Questions