【发布时间】:2010-07-22 06:49:57
【问题描述】:
这是我的第一个 JOIN 子句,我确实遇到了问题。我想回显我的项目的所有必要信息,但我不明白如何回显一个项目的所有标签,现在我得到一个包含重复项目但标签不同的列表,如果为一个项目分配了多个标签物品。有任何想法吗?也非常感谢更好的方法来做到这一点。
$query = "SELECT categories.id, categories.category, spots.spot_name, spots.category_id, spots.description, spots.slug, districts.id, districts.district, tags.spot_id, tags.tag ".
"FROM categories, spots, districts, tags ".
"WHERE categories.id = spots.category_id AND districts.id = spots.district_id AND tags.spot_id = spots.id";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
while ($row = @mysql_fetch_array($result)){
echo '<tr><td style="background:#000; color:#ccc;" class="tooltip" title="'.$row["description"].'Tags: '.$row["tag"].'"><a style="color:#fff;" href="/'.$row["slug"].'">'.$row["spot_name"].'</a></td>
<td>'.$row["category"].'</td>
<td>'.$row["district"].'</td>
<td>****</td>
</tr>
';
}
谢谢一百万,
安德斯
【问题讨论】: