Jump to content

Recommended Posts

I have a drop down that lets the user sort the records.  It looks like this:

 

<select name=\"sort_option\">
<option value="<?php echo $sort_option; ?>" SELECTED><?php echo $sort_option;?></option> 
<option value=\"business\">Business Name</option>
<option value=\"category\">Category</option>
<option value=\"start_date\">Start Date</option>
</select>

 

My problem is when it sorts, the selected option shows as the value instead of the name. In other words when the user sorts by start_date, on the following page it shows "start_date" as the first option of the drop down and I'd like it to show "Start Date".  Might this be an easy fix?

As Barand said:

 


// example array to loop options
$options = array('business' => 'Business Name',
                       'category' => 'Category',
                       'start_date' => 'Start Date');


echo "<select name='sort_option'>";

foreach ($options as $name => $value) {
   $selected = ($name == $sort_option)? "SELECTED" : "";
   echo "<option value='$name' $selected>$value</option>";
}

echo "</select>";

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.