horaliar Posted March 24, 2006 Share Posted March 24, 2006 I have the following code which populates a drop down list from a MySQL database:<html><head> <title>Imaging Scanning Log</title></head><?php//Connect to the db.require_once('mysql_connect.php');?>Select Insertion Order Number:<select name="APPNBR"> <?php //Build query to retrieve data to populate drop-down list $query = "SELECT APPNBR FROM tblAppearance"; //Execute query $result = @mysql_query($query); //Loop through the results while($row = mysql_fetch_array($result)) { //Assign returned values to the variables $APPNBR1 = $row['APPNBR'];?> <option value="<?php echo $APPNBR1;?>"><?php echo $APPNBR1;?></option> <?php } ?></select><p></p> Customer Name:<input type="text" name="custname"><p></p>Date Published:<input type="text" name="pubdate"></html>I would like to run the following query to insert the results into "custname" and "pubdate". "SELECT custname, datprd FROM tblappearance, tblcustomersWHERE tblappearance.ldgact=tblcustomers.mcustnbrAND tblappearance.appnbr=$APPNBR1"How can I do this? The only programming experience I have is with Access, and this task is accomplished so easily using this database, that I'm getting a little overwhelmed. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/5712-populate-textboxes-upon-drop-down-onchange/ Share on other sites More sharing options...
keeB Posted March 24, 2006 Share Posted March 24, 2006 You're not forming your question very well..After reading it quite a bit I found out what you meant![code]<?php$query = "SELECT custname, datprd FROM tblappearance, tblcustomersWHERE tblappearance.ldgact=tblcustomers.mcustnbrAND tblappearance.appnbr=$APPNBR1";$result = mysql_query ( $query );$data = mysql_fetch_array($result); // no need to loop since we are only concerned with row 1..?>Customer Name:<input type="text" name="custname" value="<?=$data[custname];?>"><p></p>Date Published:<input type="text" name="pubdate" value="<?=$data[datprd];?>"></html>[/code]Should get ya what you're thinking of [= Quote Link to comment https://forums.phpfreaks.com/topic/5712-populate-textboxes-upon-drop-down-onchange/#findComment-20383 Share on other sites More sharing options...
horaliar Posted March 24, 2006 Author Share Posted March 24, 2006 Thanks! What I am really looking for is that the textboxes be updated every time a selection is made. I enclosed your code in a function:<?phpfunction mine(){ $query = "SELECT custname, datprd FROM tblappearance, tblcustomers WHERE tblappearance.ldgact=tblcustomers.mcustnbr AND tblappearance.appnbr=$APPNBR1"; $result = mysql_query ( $query ); $data = mysql_fetch_array($result); // no need to loop since we are only concerned with row 1..}?>And I tried calling it using the onchange event, but I don't think I'm using the right syntax:<select name="APPNBR" onchange="<?php "mine" ?>">"Any ideas? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/5712-populate-textboxes-upon-drop-down-onchange/#findComment-20388 Share on other sites More sharing options...
horaliar Posted March 24, 2006 Author Share Posted March 24, 2006 I did some reading and found out that I can't do it this way, that I have to reload the form and run the code from JavaScript? Quote Link to comment https://forums.phpfreaks.com/topic/5712-populate-textboxes-upon-drop-down-onchange/#findComment-20401 Share on other sites More sharing options...
keeB Posted March 24, 2006 Share Posted March 24, 2006 [!--quoteo(post=358068:date=Mar 24 2006, 09:39 PM:name=Horalia)--][div class=\'quotetop\']QUOTE(Horalia @ Mar 24 2006, 09:39 PM) [snapback]358068[/snapback][/div][div class=\'quotemain\'][!--quotec--]I did some reading and found out that I can't do it this way, that I have to reload the form and run the code from JavaScript?[/quote]Well.. JavaScript and PHP can function together using a method known as AJAX.. which seems to be what you want to do. Quote Link to comment https://forums.phpfreaks.com/topic/5712-populate-textboxes-upon-drop-down-onchange/#findComment-20427 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.