简单的php / mysql问题

时间:2010-07-12 10:22:01

标签: php mysql

我的论坛上有一个“跳转到”选择框。

我想要在selectmenu中选择我正在查看的主题的论坛。

我试过了:

$threadinfo = mysql_query("SELECT * FROM threads WHERE id = $threadid");
$thread = mysql_fetch_assoc($threadinfo);

$forums = mysql_query("SELECT * FROM forums ORDER BY name ASC");

while($forum = mysql_fetch_object($forums)) {

// select the forum that the thread currently viewed is located in
if ($forum->id == $thread->fid)
 echo '<option value="'.$board->id.'" SELECTED>'.htmlspecialchars($board->name).'</option>';
else
    echo '<option value="'.$forum->id.'">'.htmlspecialchars($forum->name).'</option>';
}

但它没有选择正确的。

我目前正在查看线程#2,其中fid = 2,但它在选择菜单中选择论坛#4 ./

1 个答案:

答案 0 :(得分:1)

这有点吗?

$thread = mysql_fetch_assoc

您将其引用为代码中的对象,而不是引用的数组

$thread->fid