2010-07-12 90 views
0

我在我的論壇上有一個「Jump To」選擇框。簡單的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,但在選擇菜單./

+0

? – BoltClock 2010-07-12 10:26:19

+1

也許這是因爲您在'selected'代碼中使用'$ board'變量而不是'$ forum'變量。 – NikiC 2010-07-12 10:26:23

+0

而且你也應該把它合理化爲一個單一的數據庫查詢......它會更快 – 2010-07-12 10:28:50

回答

1

是該位正確選擇論壇#4?

$thread = mysql_fetch_assoc 

你爲什麼要使用對象符號來引用$線程,因爲你取它作爲關聯數組引用它像一個對象的代碼,而不是一個數組作爲獲取

$thread->fid