大家好,我有一些关于mysql查询的问题。我有一些这样的代码
SELECT site.id, site.name_site, site.id_site,site.id_mast,site.address,site.types,
site.longtitude,site.latitude,site.altitude, site.id_region as site,
region.name_region, region.id_region as region
FROM site as site
INNER JOIN region as region
ON site.id_region = region.id_region ORDER BY name_site limit 3;
还有这项工作:
SELECT * FROM site, region WHERE site.id_region= region.id_region LIMIT 2;
在浏览器上什么都没有发生,mysql 上的 byte 可以工作,但 PHP 上没有。为什么我在脚本 php 上有一些错误或查询 mysql 有问题?请帮我。感谢所有提示。
<?php
$dbhost = '............';
$dbuser = '........';
$dbpass = '.......';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$sql = ("SELECT * FROM site, region WHERE site.id_region= region.id_region LIMIT 2;");
mysql_select_db('db_site', $conn) or die ('Invalid query: ' . mysql_error());
?>
<h4><center>Title</center></h4>
<table border='2' cellspacing='0' cellpadding='0'>
<tr>
<td>id</td>
<td>id_site</td>
<td>id_mast</td>
<td>name_site</td>
<td>address</td>
<td>types</td>
<td>longtitude</td>
<td>latitude</td>
<td>altitude</td>
<td>id_region</td>
</tr>
<?php
$retval = mysql_query( $sql, $conn ) or die ('Error did not connection'. mysql_error());
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
print "<tr>";
print "<td>{$row['id']}</td>";
print "<td>{$row['id_site']}</td>";
print "<td>{$row['id_mast']}</td>";
print "<td>{$row['name_site']}</td>";
print "<td style='width:100;'>{$row['address']}</td>";
print "<td style='width:100;'>{$row['types']}</td>";
print "<td>{$row['longtitude']}</td>";
print "<td>{$row['latitude']}</td>";
print "<td>{$row['altitude']}</td>";
print "<td>{$row['id_region']}</td>";
print "</tr>";
}
print "</table>";
mysql_close($conn);
?>
感谢所有提示。谢谢