我可以以某种方式只使用1 sql查询呢?我该如何改进此代码?
showthread.php
// Get Topic subject etc
$threadID = isset($_GET['threadID']) ? intval($_GET['threadID']) : 0;
$result = mysql_query("SELECT * FROM topics WHERE id = $threadID");
// Fetch rows
$row = mysql_fetch_assoc($result);
$subject = htmlspecialchars($row['subject']);
echo '<h2>'.$subject.'</h2>';
// Get posts that belong to this topic!
$posts = mysql_query("SELECT * FROM posts INNER JOIN users ON users.id = posts.user_id WHERE posts.topic_id = $threadID");
// posts.....
while ($post = mysql_fetch_assoc($posts)) {
echo '<br>'.$post['message'].'';
}
你为什么要这么做? – jisaacstone 2011-06-07 01:55:36
这可能更适合http://codereview.stackexchange.com。 – 2011-06-07 01:55:52
如果你在这里没有得到很好的回应,你应该尝试在[codereview.stackexchange.com](http://codereview.stackexchange.com/) – 2011-06-07 01:56:22