Jump to content


Photo

Retrive data from drop down box via mysql


  • Please log in to reply
5 replies to this topic

#1 avo

avo
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts
  • Locationstaffordshire uk

Posted 14 April 2006 - 02:12 PM

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


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"];


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.


buster

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

my drop down table
in HTML

          </select>
        <select name="select">
          <option>gavin</option>
          <option>buster</option>
          <option>mark</option>
        </select>

Thanks in Advance
Im loving it ........

#2 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 14 April 2006 - 02:37 PM

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?


#3 avo

avo
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts
  • Locationstaffordshire uk

Posted 14 April 2006 - 02:53 PM

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)

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

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
Im loving it ........

#4 avo

avo
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts
  • Locationstaffordshire uk

Posted 14 April 2006 - 04:11 PM

Hi


Can Anyone help me with this one please


thanks.
Im loving it ........

#5 jcbarr

jcbarr
  • Members
  • PipPipPip
  • Advanced Member
  • 219 posts

Posted 14 April 2006 - 08:59 PM

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;

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']; }  }

Have your form do this;

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

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.

#6 avo

avo
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts
  • Locationstaffordshire uk

Posted 14 April 2006 - 09:24 PM

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.
Im loving it ........




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users