什麼是合併這些語句的正確語法?我不確定它加入功能使用correct Join語法
<?php
$tag_shows_result = mysql_query("SELECT *
FROM tags
WHERE tagname = '$n'
AND `show` > 0");
while ($row = mysql_fetch_array($tag_shows_result)) {
$shows_to_tag_result = mysql_query("SELECT *
FROM shows
WHERE id = ".$row['show']."
ORDER BY name ASC");
while ($row = mysql_fetch_array($shows_to_tag_result)) {
?>
<a href="./show.php?id=<?php echo $row['id']; ?>" title="<?php echo $row['name']; ?>"><img src="./images/shows/<?php echo $row['id']; ?>.jpg" width="150" height="150" border="0" alt="<?php echo $row['name']; ?>" /></a>
<?php } } ?>
了在這裏工作是正確的格式
<?php
$tag_shows_result2 = mysql_query("SELECT * FROM tags JOIN shows ON tags.show = shows.id WHERE tagname='$n' AND `show` > 0 ORDER BY shows.name ASC");
while ($row = mysql_fetch_array($tag_shows_result2))
{
?>
<a href="./show.php?id=<?php echo $row['id']; ?>" title="<?php echo $row['name']; ?>"><img src="./images/shows/<?php echo $row['id']; ?>.jpg" width="150" height="150" border="0" alt="<?php echo $row['name']; ?>" /></a>
<?php } ?>
兩個MySQL查詢結果存儲是同一個變量'$ row' ......不是正確的方式 – diEcho
並不重要的唯一的事情IM與調用第一個查詢是show id,它與shows表中的show id相同 – rackemup420