SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: using LIST

  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    Pakistan
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    using LIST

    my problem is thah when my form is loaded i populate a list with a database query. now when user selects a value from the list. on "onChange" another query runs and other fields on the form are populated according to the value selected by the user but at this time when page is loaded again and the fields on the form are filld. every thing goes write but the select list doesn't have the same value selected that was selected by the user...the selected list shows the default valuse selected instead...
    i want to know that how can we do this that when we select a value from the list and page is populated using this vale and refreshed then again i want to see the selected value in the list box not the dafault value
    regards

  2. #2
    SitePoint Enthusiast ArgentinaCoders's Avatar
    Join Date
    Nov 2003
    Location
    Argentina
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To easy! ;-)

    PHP Code:
    <select name="select_name">
    <?
    $sql 
    "SELECT id, name FROM some_table WHERE ... ";
    $result mysql_query($sql);
    if (
    $row mysql_fetch_array($result)){
        do{
             if (
    $row[id] == $select_name){
                 
    $selected "selected";
             }else{
                 unset(
    $selected);
            }
             echo 
    "<option $selected value='$row[id]'>$row[name]</option>\n";
          }while(
    $row mysql_fetch_array($result));
    }else{
             echo 
    "<option value=''>'>No data</option>\n";
    }
    </
    select>


Bookmarks

Posting Permissions

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