Jump to content

Archived

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

avo

Retrive data from drop down box via mysql

Recommended Posts

HI All

Wounder if you can help me solve this one please .

what im doing is calling the db and retriving data from it and displaying it .This is the code bellow

[code]

if($_POST['subEdit']){
    mysql_connect($dbhost, $dbuser, $dbpass);
    mysql_select_db($dbname);
    $sql = mysql_query("SELECT username ,name ,lname, waddress, pnumber, mnumber, email, ainfo, dateinfo FROM memlist WHERE  username=buster");               
    }
    while($result = mysql_fetch_array($sql))
    {
    $username =  "" .$result["username"];
    $name =  "" .$result["name"];
    $lname =  "" .$result["lname"];
    $waddress =  "" .$result["waddress"];
    $pnumber =  "" .$result["pnumber"];
    $mnumber =  "" .$result["mnumber"];
    $email =  "" .$result["email"];
    $ainfo =  "" .$result["ainfo"];
    $dateinfo =  "" .$result["dateinfo"];

[/code]

But this bit of the code (buster )i would like it to point at a drop down box so when i select a user from the drop down this is then iserted into this section me clicking th button will then result in the code execution with the selected name from the dropdoown box.

[code]

buster

dateinfo FROM memlist WHERE  username=[quote]buster[/quote]");        
[/code]

my drop down table
in HTML

[code]
          </select>
        <select name="select">
          <option>gavin</option>
          <option>buster</option>
          <option>mark</option>
        </select>
[/code]

Thanks in Advance

Share this post


Link to post
Share on other sites
I'm trying to understand your question:

Are you trying to do a query, create a pulldown based on the result, then submit a second query based on what the user selects from the pulldown?

Share this post


Link to post
Share on other sites
HI thanks for getting back to me

what i have is a pull down list on my page ive added names to that list when i select one of them names i want that name to apper as ive i have typed it in the code (in place of buster)

[code]
    $sql = mysql_query("SELECT username ,name ,lname, waddress, pnumber, mnumber, email, ainfo, dateinfo FROM memlist WHERE  username=buster");
[/code]

then this will give me the results i need

at the moment for example if i type the name buster in it will get the information i need from the db

hope i explaned ok


thanks again

Share this post


Link to post
Share on other sites
Hi


Can Anyone help me with this one please


thanks.

Share this post


Link to post
Share on other sites
So what you want is the drop down box full of names on your page. When you select the name from the drop down you want it to display all their information that is in the database correct? If that is hat you want to do; try something like this;

[code]if($_POST['subEdit']){
    mysql_connect($dbhost, $dbuser, $dbpass);
    mysql_select_db($dbname);
    $user=$_POST['user'];
    $sql = mysql_query("SELECT username ,name ,lname, waddress, pnumber, mnumber, email, ainfo, dateinfo FROM memlist WHERE  username='$user'");                
    
    while($result = mysql_fetch_array($sql))
    {
    $username =  $result['username'];
    $name =  $result['name'];
    $lname = $result['lname'];
    $waddress = $result['waddress'];
    $pnumber = $result['pnumber'];
    $mnumber = $result['mnumber'];
    $email =  $result['email'];
    $ainfo =  $result['ainfo'];
    $dateinfo =  $result['dateinfo']; }  }[/code]

Have your form do this;

[code]
        <select name="user">
          <option>gavin</option>
          <option>buster</option>
          <option>mark</option>
        </select>[/code]

That should be a simple way to get what you want. Of course you will still have to format the output of the above script the way you want it, but that should be simple.

If I'm not mistaken I don't believe you need all thos "" and . up there either when you are setting the variables.

Share this post


Link to post
Share on other sites
HI

Thankyou for that

im sure i tryed that but must not have iv'e been on that now for a good 3 hours trying to figure out why..]


Thankyou works great.

Share this post


Link to post
Share on other sites

×

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.