1

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?

1
  • Please stop tagging your question titles. Commented Jul 21, 2011 at 13:02

1 Answer 1

1

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.

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

1 Comment

Thanks for taking the time to help me.

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.