Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jan 2006
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    auto fill with drop down menu and text boxes

    hello there,
    I am new to php mysql and i am working on a small project currently.i am facing a problem.
    can some one tell me how i can go abt the following:i have a drop down menu with say 5 student name options and a text box which displays student address.when i select one of the student name's i have to get the respective student address for the student name that i actually selected from drop down menu from my mysql database.

    thanx a lot..
    ahmed

  • #2
    Regular Coder
    Join Date
    Jul 2005
    Posts
    153
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hope that helps.


    PHP Code:
        <?

                           
            $sql 
    "SELECT data FROM table";        
                       
    $result mysql_query($sql$conn) or die(mysql_error());
                    while (
    $newArray mysql_fetch_array($result)) {      
                           
                         
    $data$newArray['data'];   
    }
    ?>

    <input type="text" name="textfield" value="<? echo "$data"?>" />

  • #3
    New Coder
    Join Date
    Jan 2006
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    thanx...

    hey thanx for the suggestion.......
    i want some thing like this......selecting a value in the drop down menu and based on selection the respective data from the database should be autofilled into the other textboxes....there shud be no button click...

    thanx ahmed


    Quote Originally Posted by simjay
    Hope that helps.


    PHP Code:
        <?

                           
            $sql 
    "SELECT data FROM table";        
                       
    $result mysql_query($sql$conn) or die(mysql_error());
                    while (
    $newArray mysql_fetch_array($result)) {      
                           
                         
    $data$newArray['data'];   
    }
    ?>

    <input type="text" name="textfield" value="<? echo "$data"?>" />

  • #4
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If using pure PHP then you need to submit the form.
    You can have an onchange event using javascript.

    http://computer-helpforum.com/php/co...ulate_form.php
    It uses a standard query. The value of the select is used in the query.

  • #5
    New Coder
    Join Date
    Jan 2006
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    hey thanx degsy

    hey degsy thanx a lot dude...that is what i actually wanted.....i have one more doubt.....i am implementing this in a add form .....so calling the whole form to submit will invoke my php add code also right?...can u tell me how i can go about it...like how do i jus invoke the drop down code alone......sorry if i am asking u anything silly....jus bear with me...i am a beginner....it would be great if u can jus help me a little.

    thanx ahmed

    Quote Originally Posted by degsy
    If using pure PHP then you need to submit the form.
    You can have an onchange event using javascript.

    http://computer-helpforum.com/php/co...ulate_form.php
    It uses a standard query. The value of the select is used in the query.
    Last edited by afma_afma; 05-03-2006 at 06:57 PM.

  • #6
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's a basic query.

    You have your dropdown with your options.
    When you submit it you can query the database using that variable.


    Read up here on how to query a database
    http://www.zend.com/php/beginners/php101-8.php#Heading6


    You would wany a query with a WHERE clause
    http://www.w3schools.com/sql/sql_where.asp


  •  

    Posting Permissions

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