randydg Posted June 18, 2010 Share Posted June 18, 2010 Ok here is what im trying to do: 1. drop down list pulled from mysql database. 2. after you select the name in the drop down list below the drop down list it should show the address. 3. if you select another name in the drop down list it should update the address Here is the code what am I doing wrong? the drop down menu works but it doesnt post the address thanks, Randy <?php //Get Name/Company out of database $db = mysql_connect("ip","user","pass") or die("Couldn't connect"); mysql_select_db("database",$db) or die("Couldn't select database"); $query="SELECT * FROM `customers`"; $result=mysql_query($query); $num=mysql_numrows($result); echo "<span class=\"style4\"></span><select name=\"name\" id=\"name\">"; $i=0; while ($i < $num) { $techname=mysql_result($result,$i,"name"); $address=mysql_result($result,$techname,"address"); $techid=mysql_result($result,$i,"id"); echo "<option value=$techid>$techname</option>"; $i++; }; echo "<option value=\"NA\">Other</option>"; echo "<option value=\"-\" selected>-</option> </select>"; echo "<p>Address:"; echo "$address"; //Get address out of database ?> Quote Link to comment https://forums.phpfreaks.com/topic/205195-php-drop-down-from-sql-and-post-result-bellow/ Share on other sites More sharing options...
ram4nd Posted June 18, 2010 Share Posted June 18, 2010 You pull the database in a weird way, use foreach. You need javascript to pull that off. Quote Link to comment https://forums.phpfreaks.com/topic/205195-php-drop-down-from-sql-and-post-result-bellow/#findComment-1074059 Share on other sites More sharing options...
randydg Posted June 18, 2010 Author Share Posted June 18, 2010 I had it somewhat working, where it posted the address just had trouble updating it. and as far as pulling the database, its the common way. Quote Link to comment https://forums.phpfreaks.com/topic/205195-php-drop-down-from-sql-and-post-result-bellow/#findComment-1074110 Share on other sites More sharing options...
PFMaBiSmAd Posted June 18, 2010 Share Posted June 18, 2010 Your code has no code in it to process the form submission and get the correct address to display. Any address it is currently displaying is just the address from the last row that was fetched when you built the drop-down menu. Building the form and processing the form are two separate operations and you need code to perform each operation. If you want the address to be updated without refreshing the whole page, yes you do need to use javascript (AJAX.) If you don't care if the page refreshes, you can just submit the form normally and let the whole page redisplay. Which method did whoever assigned this want you to use? And if you want the form to automatically submit when you pick a different selection in your drop-down, you will need to use an onchange event. That's also not all of your form and probably won't submit anything anyway. What is your full code on the page? Quote Link to comment https://forums.phpfreaks.com/topic/205195-php-drop-down-from-sql-and-post-result-bellow/#findComment-1074115 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.