Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-02-2006, 07:33 PM   PM User | #1
afma_afma
New Coder

 
Join Date: Jan 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
afma_afma is an unknown quantity at this point
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
afma_afma is offline   Reply With Quote
Old 05-02-2006, 11:19 PM   PM User | #2
simjay
Regular Coder

 
Join Date: Jul 2005
Posts: 153
Thanks: 1
Thanked 0 Times in 0 Posts
simjay is an unknown quantity at this point
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"?>" />
simjay is offline   Reply With Quote
Old 05-03-2006, 01:31 AM   PM User | #3
afma_afma
New Coder

 
Join Date: Jan 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
afma_afma is an unknown quantity at this point
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"?>" />
afma_afma is offline   Reply With Quote
Old 05-03-2006, 02:54 PM   PM User | #4
degsy
Senior Coder

 
Join Date: Nov 2002
Location: North-East, UK
Posts: 1,265
Thanks: 0
Thanked 0 Times in 0 Posts
degsy is on a distinguished road
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.
degsy is offline   Reply With Quote
Old 05-03-2006, 03:25 PM   PM User | #5
afma_afma
New Coder

 
Join Date: Jan 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
afma_afma is an unknown quantity at this point
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..
afma_afma is offline   Reply With Quote
Old 05-04-2006, 02:45 PM   PM User | #6
degsy
Senior Coder

 
Join Date: Nov 2002
Location: North-East, UK
Posts: 1,265
Thanks: 0
Thanked 0 Times in 0 Posts
degsy is on a distinguished road
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
degsy is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:13 AM.


Advertisement
Log in to turn off these ads.