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
https://forums.phpfreaks.com/topic/219540-combo-box-using-arrays/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.