我使用此代码输出具有特定论坛ID的所有线程
$query = mysql_query("SELECT * FROM forums JOIN threads ON threads.fid = forums.id WHERE forums.id = ".intval($_GET['forumID']));
$forum = mysql_fetch_assoc($query);
?>
<h1><a>Forums</a> > <?=$forum['name']?></h1>
<?php while ($thread = mysql_fetch_array($query)): ?>
<?=$thread['title']?>
<?php endwhile; ?>
Run Code Online (Sandbox Code Playgroud)
论坛
id, name, description
线程
id, title, message, fid
事情是它输出所有线程exept一个.如果我删除它只是隐藏另一个.这是为什么?
非常感谢一些帮助!
抱歉,我的英语不是那么好,假设我在fid =的线程中有4条记录(在这种情况下为1),它只输出3条
您正在使用第2行mysql_fetch_assoc中返回的第一行.在while循环条件中,mysql_fetch_array函数将从sql查询的第二行开始,而不是第一行.因此,列表中缺少第一行的ID.但是,如果使用列名,则还应使用mysql_fetch_assoc,而不是mysql_fetch_array.这不应该给你任何ID.