I have a MySQL table set up using phpMyAdmin which you can view in the images below:
And here is the populated table:
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_ar开发者_Python百科ray($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?
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.
精彩评论