显示查询结果的问题 [英] Problem displaying query results
问题描述
我使用 phpMyAdmin 设置了一个 MySQL 表,您可以在下图中查看:
I have a MySQL table set up using phpMyAdmin which you can view in the images below:
这是填充的表格:
我遇到的问题是,当我发出以下查询时,没有返回任何结果.我正在努力找出原因.
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?
推荐答案
mysql_query
是错误的.mysql_select_db
的结果不属于那里,查询应该是第一个参数.
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.
这篇关于显示查询结果的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!