MyBB Community Forums

Full Version: Creating a select box with the forum names?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Ok I have put a search box in my header file and want to make it so it is not just a search ALL option, but instead they can choose which forum to search from a drop down menu.

I tried modifying the header in the template file like this:


<SELECT name="forums" size="5">
<?php
$frmquery = "SELECT fid, name FROM mybb_forums WHERE type = f ORDER BY fid";
$frmresult = mysql_query($frmquery);

while($row = mysql_fetch_array($frmresult, MYSQL_ASSOC)) {
	$fid = $row['fid'];
	$name = $row['name'];
	echo "<br /><option value=\"$fid\">$name</option>";
}

?>
</SELECT>

and learnt that myBB deffinitely does not like that php code in the header file.

So my question is how do I go about it?
In global.php, find:
eval("\$header = \"".$templates->get("header")."\";");
Before that line, add:
$search_forums = '<SELECT name="forums" size="5">';
$query = $db->simple_select(TABLE_PREFIX."forums", "fid, name", "type='f'", array('order_by' => 'fid'));
while($row = $db->fetch_array($query))
{
    $search_forums .= "<option value=\"$fid\">$name</option>\n";
}
$search_forums .= "</SELECT>";
Then in my header template do I simply put the {$search_forums} like that?
Yeap Toungue