Problem displaying query results

限于喜欢 提交于 2019-12-11 07:45:30

问题


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_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:


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.



来源:https://stackoverflow.com/questions/6776410/problem-displaying-query-results

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!