Forum Moderators: coopster

Message Too Old, No Replies

Getting menu list from DB

Getting menu list from DB. When I select one, it should stay with that

         

anvarbek

2:58 pm on Feb 23, 2005 (gmt 0)

10+ Year Member



Hello,

I am doing dynamic menu list. It takes a list from DB.

And when I select an item in menu. It should submit the value and load C file.

I cant get the menu selected item be displayed after submission.

Here is the code

<form name="form2" method="post" action="<? $_SERVER <select name="events_list" size="1" id="events_list" onchange="submit()">
<option value="zero"> Please select the event </option>
<?

while($row = mysql_fetch_array( $sql2 )) {
echo " <option value=\" $row[0]\" ";

if ($_POST['events_list']) { // see if List menu is selected
$event_id = $_POST['events_list'];
}

if ( $row[0]== strval$event_id) { //THIS IS NOT WORKING
echo "selected";
}

echo "> $event_id.$row[1] </option>";

}

?>
</select>
</div>
</form>

dmmh

7:14 pm on Feb 23, 2005 (gmt 0)

10+ Year Member



I use it something like this, modify it for your needs )
$currency_selector.= "<select name=\"currency[]\" size=\"1\" class=\"menu\">\n";
$currency_selector.= "<option value=\"\" selected>select</option>\n";
{
//a query to see what currency the user may select
@mysql_select_db('DB');
$query = 'SELECT currency FROM selectors_table WHERE id IS NOT NULL AND currency IS NOT NULL';
$result = mysql_query($query) or die ("Error in query: $query " . mysql_error());
$currencies = array(); // initialize the array
if (isset($_POST['currency'])){
$currency_selected = $_POST['currency'];
}
while ($myresult = mysql_fetch_array($result)) // loop through and add each currency to array
{
$currencies[]= $myresult;
}
foreach ($currencies as $currency)
{
// build the options...
$currency_selector.= "<option value=\"$currency[0]\"";
if ($currency[0] == $currency_selected)
{$currency_selector.= " selected ";}
$currency_selector.= ">$currency[0]</option>\n";
}
// close the select tags
$currency_selector.= "</select>"; }

because I use this one on multiple pages, I also user $_SERVER['DOCUMENT_ROOT'] to determine the requesting scripts name to determine what $currency_selected should contain, a value from a field received from a query or a simple $_POST value, like is included in the example. I left the rest out for your ease of understanding it :) Its inside a file, which I include and I use the selector like: <? echo $currency_selector;?>

thats about it :)

anvarbek

7:23 pm on Feb 23, 2005 (gmt 0)

10+ Year Member



Thanks buddy!

On the way to digest it :)

dmmh

7:42 pm on Feb 23, 2005 (gmt 0)

10+ Year Member



any questions, just pop them :)