Jump to content

combo box using arrays


doddsey_65

Recommended Posts

i am trying to create a combo box so the user can order topics by asc or desc. The problem is trying to get the name of the option to Ascending or Descending and the value to asc or desc. Heres what i have so far:

 

$order_name = array('Ascending', 'Descending');
$order_value = array('asc' => 'Ascending', 'desc' => 'Descending');

echo "<div style=\"float:right;\">";
echo "<form name=\"order_form\" action=\"{$site_root}/index.php\" method=\"GET\">";
echo "<input type=\"hidden\" value=\"{$forum_id}\" name=\"forum\" />";

echo "<select name=\"order_by\" style=\"margin-left:5px;\">";
foreach ($order_name as $i)
{
echo "<option name=\"order_by_option\" value=\"{$order_value}\"/>";
echo "Order By: {$i}";
echo "</option>";
}

echo "</select>";

 

when i try to order them the GET value is Array.

 

Any ideas?

Link to comment
Share on other sites

ok here is the form html when viewing source:

 

<form name="order_form" action="http://localhost/myforum/index.php" method="GET">
<input type="hidden" value="1" name="forum" />
<select name="order_by" style="margin-left:5px;">
<option name="order_by_option" value="Array"/>
Order By: Ascending
</option>
<option name="order_by_option" value="Array"/>
Order By: Descending
</option>
</select>
<input type="submit" value="Order" />
</form>

 

Basically all i want to do is have Order By: Ascending and the relevent option value to be asc

or Order: By Descending and its option value to be desc. I thought I could use an array like:

 

$order_name = array('Ascending', 'Descending');
$order_value = array('asc' => 'Ascending', 'desc' => 'Descending');

 

and then have a foreach loop to echo the options for how ever many there are in the array like so:

 

foreach ($order_name as $i)
{
echo "<option name=\"order_by_option\" value=\"{$order_value}\"/>";
echo "Order By: {$i}";
echo "</option>";
}

 

the order by is fine, it lists the options Ascending and Descending. but it doesnt give them the proper values (asc, desc). instead it just assigns the value array.

Link to comment
Share on other sites

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.