...

View Full Version : auto fill with drop down menu and text boxes



afma_afma
05-02-2006, 07:33 PM
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

simjay
05-02-2006, 11:19 PM
Hope that helps.



<?


$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
05-03-2006, 01:31 AM
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



Hope that helps.



<?


$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"; ?>" />

degsy
05-03-2006, 02:54 PM
If using pure PHP then you need to submit the form.
You can have an onchange event using javascript.

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

afma_afma
05-03-2006, 03:25 PM
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


If using pure PHP then you need to submit the form.
You can have an onchange event using javascript.

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

degsy
05-04-2006, 02:45 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum