【发布时间】:2012-01-12 17:26:29
【问题描述】:
我很难将 mysql 数据库中的数据显示到 PHP 生成的表中。有趣的是,下面显示的查询在 SQL 中运行良好,但是当我尝试将其包装在 PHP 中时,它显示空表而没有给出任何错误。
SELECT city.name, cinema.name, whattime, whichdate
FROM city, cinema, relationship
WHERE cinema.city = city.id
AND cinemaid = cinema.id
ORDER BY whichdate
这是 PHP 代码:
<?php
$usr = "admin";
$pwd = "";
$db = "dbname";
$host = "localhost";
$con = mysql_connect($host, $usr, $pwd) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
$sql = "select city.name, cinema.name, whichdate, whattime ";
$sql .= "from city, cinema, relationship ";
$sql .= "where cinema.city = city.id ";
$sql .= "and cinemaid = cinema.id ";
$sql .= "order by whichdate";
$query = mysql_query($sql, $con) or die(mysql_error());
echo "<table id='premiere'>";
echo "<tr> <th>CITY</th> <th>CINEMA</th> <th>DATE</th> <th>TIME</th></tr>";
while($result = mysql_fetch_array( $query )) {
echo "<tr><td>";
echo $result['city.name'];
echo "</td><td>";
echo $result['cinema.name'];
echo "</td><td>";
echo $result['relationship.whichdate'];
echo "</td><td>";
echo $result['relationship.whattime'];
echo "</td></tr>";
}
echo "</table>";
?>
任何帮助将不胜感激。
【问题讨论】:
-
你检查过mysql_error()的结果了吗?您是否尝试过一个您知道会返回结果的更简单的查询,例如“select 1;”?尝试使用 mysqli 而不是 mysql 函数。
标签: php mysql sql html-table