gpt4 book ai didi

php - 正确的连接语法

转载 作者:行者123 更新时间:2023-11-29 04:03:30 24 4
gpt4 key购买 nike

合并这些语句的正确语法是什么?我不确定要使用哪个连接函数

<?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)) {
?>
&nbsp;<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))
{
?>
&nbsp;<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 } ?>

最佳答案

无需花哨:

SELECT show.* FROM tags
JOIN shows ON (tags.show = show.id)
WHERE tags.tagname = ?
ORDER BY show.name ASC

或者,更简单:

SELECT * FROM shows WHERE id IN (
SELECT show FROM tags WHERE tagname = ?
) ORDER BY name ASC

关于php - 正确的连接语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6628237/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com