我有两张桌子classifieds
和state
.
分类广告 -id, title, state_id
状态 -id, statename
我正在尝试从州中呼出州名。我试过这个查询,但它只回显最后一行。
<?php
$query = "SELECT * FROM classifieds ";
$result = mysql_query($query) or die(mysql_query());
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
?>
<div>
<span>Title: <?php echo $row['title'];?> </span>
</div>
<div>
<span>Name: <?php echo $row['name'];?> </span>
</div>
$q = mysql_query("SELECT * FROM classifieds AS C
LEFT JOIN state AS S
ON C.state_id = S.id");
$z = array();
while($state=mysql_fetch_array($q))
{
array_push($z,$state["statename"]);
}
?>
<div>
<span>State: <?php foreach($z as $location) { echo $location; } ?></span>
</div>
<?php } // End of the first while loop ?>
谢谢