当用户选择单个值时,显示数据库中的数据

I am trying to display the data from the database when a dropdown value is selected by the user. There is dropdown for all the registered members. when a admin user selects a registered member name from the drop down it has to populate all the details for that member.

My selection box code is like this

if ($_SESSION['admin_privs'] == "yes" || $_SESSION['edit_all_listings'] == "yes") {
                    $display .= '<tr><td align="right"><strong>' . $lang['listing_editor_listing_agent'] . ':</strong></td>';
                    $display .= '<td align="left" class="row_main">';

                    $agent_select = array();                    
                    // find the name of the agent listed as ID in $edit_or_owner
                    $sql = "SELECT userdb_user_first_name, userdb_user_last_name FROM " . $config['table_prefix'] . "userdb WHERE (userdb_id = $_SESSION[userID])";
                    $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
                    $recordSet = $conn->Execute($sql);
                    if ($recordSet === false) {
                        $misc->log_error($sql);
                    }
                    // strip slashes so input appears correctly
                    $agent_first_name = $misc->make_db_unsafe($recordSet->fields['userdb_user_first_name']);
                    $agent_last_name = $misc->make_db_unsafe($recordSet->fields['userdb_user_last_name']);
                    if ($_SESSION['admin_privs'] != "yes")
                    {
                        $agent_select[$_SESSION['userID']] = $agent_last_name.','.$agent_first_name;
                    }
                    // fill list with names of all agents
                    $sql = "SELECT userdb_id, userdb_user_first_name, userdb_user_last_name FROM " . $config['table_prefix'] . "userdb where userdb_is_agent = 'yes' or userdb_is_admin = 'yes' ORDER BY userdb_user_last_name,userdb_user_first_name";
                    $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
                    $recordSet = $conn->Execute($sql);
                    if ($recordSet === false) {
                        $misc->log_error($sql);
                    }
                    while (!$recordSet->EOF) {
                        // strip slashes so input appears correctly
                        $agent_ID = $recordSet->fields['userdb_id'];
                        $agent_first_name = $misc->make_db_unsafe($recordSet->fields['userdb_user_first_name']);
                        $agent_last_name = $misc->make_db_unsafe($recordSet->fields['userdb_user_last_name']);
                        if ($agent_ID == $_SESSION['userID']) {
                            $agent_select[$agent_ID] = $agent_last_name.','.$agent_first_name;
                            $selected = $agent_ID;
                        }else {
                            $agent_select[$agent_ID] = $agent_last_name.','.$agent_first_name;
                        }
                        $recordSet->MoveNext();
                    }
                    $display .= $form->selectBox($agent_select, $selected, 'or_owner');
                    $display .= "</td>";
                    $display .= '</tr>';
                }

I have different function for forms , like this

function selectBox($array, $selected='', $name='', $size=1, $multiple=false, $additional='') { 
    $res = ''; 
    static $count = 0; 
    if (is_array($array)) { 
        if ($name == '') { 
            $name = 'selectBox' . ++$count; 
        }

        $res .= "<select name=\"$name\" size=\"$size\"" . ($multiple==false ? '' : " multiple=\"multiple\"") . ($additional ? " $additional" : '') . ">
"; 
        $i = 0; 
        foreach($array as $key => $value) { 
            $res .= "<option value=\"$key\"" . ($key == $selected ? " selected=\"selected\"" : '') . ">$value</option>
"; 
        } 
        $res .="</select>
"; 
    }


    return $res; 
} 


    function textField($value, $name='', $hidden=false, $size =-1, $length =-1, $additional='') { 
        $res = ''; 
        static $count = 0; 
        if ($name == '') { 
            $name = 'textField' . ++$count; 
        } 
        $res .= "<input name=\"$name\" type=\"" . ($hidden ? 'password' : 'text') . "\" value=\"$value\""; 
        $res .= ($size != -1 ? " size=\"$size\"" : ''); 
        $res .= ($length != -1 ? " maxlength=\"$length\"" : ''); 
        $res .=  ($additional ? " $additional" : '') . ">"; 
        return $res; 
    } 

Now i want to display the details of selected user from database, can somebody tell me how can i achieve this :( thanks

I am not from php but after looking your code its look like your session cause this problem try to debug from session points..

This can best be achieved using AJAX. There is a tutorial on w3schools.com which explains how ajax works. You will simply have to modify the code they supply.

Fundamentally, what you need is:

<SELECT name='name' id='123' onchange='userhint(this.value)'><OPTION value='usercode'...

As your select. The key is putting the onchange call in the SELECT.

You will also need a form goes here

The JS looks like:

function userhint(str)
{

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("changingdiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","myphpfile.php?q="+str,true);
xmlhttp.send();
}

This will replace the content of 'changingdiv' with whatever myphpfile.php returns in response to a get request of q. You are clearly capable of writing that file yourself.

Depending on how you want to do it, the php can either create the complete HTML of the new div or return a json string which you can then use to populate your original areas. For a beginner, the first option is definitely easiest (and is expected by the very basic js above) but the json method will use a fair bit less bandwidth and makes it easier to re-use the same file to feed multiple pages.