我使用php while循环和mysql_fetch_array将一些数据从mysql输出到div中。这一切都运行良好,但我正在努力的是..我希望数据从两列列的数量上升。但是这两列是在一个由外键链接的不同表中(我在phpmyadmin中设置),所以目前我是:
$query= mysql_query("SELECT * FROM venue WHERE idLocation = $idLocation");
while($row = mysql_fetch_array($query)) {
$idVenue = $row['idVenue'];
$locationName = $row['name'];
$query_counter_resturant = "SELECT `idResturant` FROM `myTable`
WHERE `idResturant` = '$venue_id'";
$query_run_counter_resturant = mysql_query($query_counter_resturant);
$counter_resturant = mysql_num_rows($query_run_counter_resturant);
$query_counter_cafe = "SELECT cafe FROM myTable
WHERE cafe ='$venue_id'";
$query_run_counter_cafe = mysql_query($query_counter_cafe);
$counter_cafe = mysql_num_rows($query_run_counter_cafe);
$counter = $counter_resturant + $counter_cafe;
?>
<div>
<p> <?php echo $locationName ?> </p>
<P> <?php echo $counter ?> </p>
</div>
所以基本上我希望它按$ counter升序排序..无论如何要做到这一点?