Reputation: 1567
what would be the right syntax to merge these statements? i am unsure of which join function to use
<?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 } } ?>
Got it working here is the correct format
<?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 } ?>
Upvotes: 1
Views: 73
Reputation: 54016
try
SELECT s.id, s.name FROM `shows` s
INNER JOIN tags t ON t.id=s.show
WHERE t.tagname='$n'AND s.`show` > 0
and then display whatever manner u want..
ALL D BEST :)
Upvotes: 2
Reputation: 27486
Maybe:
SELECT tags.id, tags.name
FROM tags, shows
WHERE tags.tagname = '$n' and shows.id = tags.show and tags.show>0
Upvotes: 0
Reputation:
No need to get fancy:
SELECT show.* FROM tags
JOIN shows ON (tags.show = show.id)
WHERE tags.tagname = ?
ORDER BY show.name ASC
Or, even simpler:
SELECT * FROM shows WHERE id IN (
SELECT show FROM tags WHERE tagname = ?
) ORDER BY name ASC
Upvotes: 3
Reputation: 360592
SELECT *
FROM tags
JOIN shows ON tags.show = shows.id
WHERE tagname='$n' and show>0
Guessing at the fields used in the joy, but this should be about what you want.
Upvotes: 2