Three queries - whiled within each other (Cut them down?)
Posted: Mon Oct 25, 2004 6:29 pm
Im wondering if theres some other method you guys can show me to accomplish this code with less queries.
Im aware its set out weird or unreable (im sorry, its just my style) so it might look quite alot, but its actually quite simple.
A working example can be seen here; http://forumz.wuggawoo.co.uk/index/test
Im aware its set out weird or unreable (im sorry, its just my style) so it might look quite alot, but its actually quite simple.
Code: Select all
function forum_dropdown($selected, $altLocations)
{global $forumzDB, $user_properties;
$query_categories = query("SELECT cat_title, cid FROM $forumzDB.forumz_categories ORDER BY `order`") or die_query("fuction_forum_dropdown_1");
while($categ = mysql_fetch_object($query_categories)) {
$forum_output = '';
$query_forums = query("SELECT forum_title, fid FROM $forumzDB.forumz_forums
WHERE level <= ".$user_properties['status_id']."
AND type != 'lock' AND subFID = '' AND cid = '$categ->cid'
ORDER BY `order`") or die_query("fuction_forum_dropdown_2");
while($forum = mysql_fetch_object($query_forums)) {
$selected_html = '';
if($selected == $forum->fid)
{$selected_html = ' selected = "selected"';}
$forum_output .= "<option value="".$forum_properties['base_url']."forum/$forum->fid"$selected_html> -- $forum->forum_title</option>";
$query_subs = query("SELECT forum_title, fid FROM $forumzDB.forumz_forums
WHERE level <= ".$user_properties['status_id']."
AND type != 'lock' AND subFID = '$forum->fid'
ORDER BY `order`") or die_query("fuction_forum_dropdown_3");
while($subs = mysql_fetch_object($query_subs)) {
$selected_html = '';
if($selected == $forum->fid)
{$selected_html = ' selected = "selected"';}
$forum_output .= "<option value="".$forum_properties['base_url']."forum/$subs->fid"$selected_html> ---- $subs->forum_title</option>";
}#end sub forums
}#end forum
if($forum_output)
{$output = $output.'<option></option>
<option>Category : '.$categ->cat_title.'</option>'.$forum_output;}
}#end categ
if($altLocations == 1)
{$alt_locations = "<option value="".$forum_properties['base_url']."">Home</option>
<option value="".$forum_properties['base_url']."active_topics">Active Topics</option>
<option value="".$forum_properties['base_url']."online_users">Online Users</option>
<option value="".$forum_properties['base_url']."memberslist">Memberslist</option>
<option value="".$forum_properties['base_url']."edit_account">Control Panel</option>";}
return '<form name="dropdownForm"><select onchange="window.location=document.dropdownForm.dropdownOptions.options[document.dropdownForm.dropdownOptions.selectedIndex].value" name="dropdownOptions" class="textfield">
'.$alt_locations.$output.'</select></form>';}
echo forum_dropdown(16, 1);