Dynamic Jump Menu with selected option

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Glorfindel
Forum Newbie
Posts: 1
Joined: Fri Apr 09, 2004 11:32 am

Dynamic Jump Menu with selected option

Post by Glorfindel »

I am building a jump menu which is populated from a database. I am needing the jump menu to have a specific option be selected which is also provided from a seperate database. The populating of the menu is not a problem but I can not get the selected value part to work. Here is the code that was provided from a colleague which does not work.

Code: Select all

$selectedproject=$timelistїprojectcategory];
   $projectselectedї$selectedproject]="selected";
   $projectquery="select * from projectcategories order by description asc";
   $projectresult=mysql_query($projectquery);
   $projectcount=mysql_num_rows($projectresult);
   $projectcounter=0;		
      while ($projectcounter < $projectcount)&#123;
         $project=mysql_fetch_array($projectresult);
         $projectselector=$projectselected&#1111;$project&#1111;projectcategory]];
         $projectselected&#1111;$projectselector]="selected";
         $projectlist.="<option value="$project&#1111;name]" $projectselector>$project&#1111;description]</option>";
         $projectcounter++;
         &#125;
Thanks for all replies
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

I'm presuming $selectedproject=$timelist[projectcategory]; is the one which should be selected, if so then something like the following should do it,

Code: Select all

$selectedproject=$timelist['projectcategory'];
$projectquery="select * from projectcategories order by description";
$projectresult=mysql_query($projectquery) or die(mysql_error());
$projectlist = '';
while ($project = mysql_fetch_assoc($projectresult)){
  $project=mysql_fetch_array($projectresult);
  $projectlist.= '<option value="'.$project['name'].'"';
  if($project['name'] == $selectedproject){
    $projectlist .= ' selected';
  }
  $projectlist .= '>'.$project['description'].'</option>';
  $projectcounter++;
}
Post Reply