Results 1 to 3 of 3
  1. #1

    How do I change this drop down menu function?

    I wrote this function for a drop down menu but I want to keep the "selected" value as the chosen value.

    Any help appreciated.

    PHP Code:
    function promo_drop_down() {
    $sql "SELECT a.p_id, a.cat_id, a.name, b.name, date_format(b.start_date, '%c') as Month, date_format(b.start_date, '%Y') as Year FROM tbl_categories a, tbl_promotion b where a.p_id=b.p_id";
    $rsBPromo rsMySqlPromo($sql);
    $rsBPromo->MoveFirst();
    echo 
    "<select name=\"newurl\"  onchange=\"menu_goto(this.form)\">";
    while (!
    $rsBPromo->EOF)
    {
    echo 
    "<option value=\"?month=".$rsBPromo->fields[4]."&year=".$rsBPromo->fields[5]."&p_id=".$rsBPromo->fields[0]."&c_id=".$rsBPromo->fields[1]."\">".$rsBPromo->fields[2]."</option>";
    $rsBPromo->MoveNext();
    }
    echo 
    "</select>";


  2. #2
    Join Date
    Mar 2003
    Location
    South Bend, Indiana, USA
    Posts
    320
    What about changing the code to something like:
    PHP Code:
    function promo_drop_down() {
    $sql "SELECT a.p_id, a.cat_id, a.name, b.name, date_format(b.start_date, '%c') as Month, date_format(b.start_date, '%Y') as Year FROM tbl_categories a, tbl_promotion b where a.p_id=b.p_id";
    $rsBPromo rsMySqlPromo($sql);
    $rsBPromo->MoveFirst();
    echo 
    "<select name=\"newurl\"  onchange=\"menu_goto(this.form)\">";
    while (!
    $rsBPromo->EOF) {
    $url "month=".$rsBPromo->fields[4]."&year=".$rsBPromo->fields[5]."&p_id=".$rsBPromo->fields[0]."&c_id=".$rsBPromo->fields[1];
    echo 
    '<option value="?'.$url.'"'.(($url == $_SERVER['QUERY_STRING']) ? ' selected' '').'>'.$rsBPromo->fields[2].'</option>';
    $rsBPromo->MoveNext();
    }
    echo 
    "</select>";

    Daniel
    WLScripting.com - php scripts and tutorials

  3. #3

    Works great but...

    It only works when the month and year = $rsBPromo->fields[4] and $rsBPromo->fields[5]

    When I toggle between months, it doesn't work.

    It's Friday. I'm tired. I'll look at it on Monday.

    Thanks for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •