spbryantusa Posted January 21, 2009 Share Posted January 21, 2009 I have a drop down menu that gets its values from a Mysql database. What I want to do is once someone chooses the company they want it will give me the phone number and email that is in the database for that company. <? $dbhost = "localhost"; $dbname = "name"; $dbuser = "user"; $dbpass = "pass"; mysql_connect($dbhost,$dbuser,$dbpass); mysql_select_db($dbname); $sql="select * from via"; $result=mysql_query($sql); $zeile = mysql_fetch_array($result); ?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <?php $query5 = "select * from via ORDER BY Customer_Company"; echo "<select name=\"Customer_Company\">"; $result5 = mysql_query($query5); echo "<OPTION selected>$Customer_Company"; while ($row=mysql_fetch_array($result5)) { $Customer_Company=$row["Customer_Company"]; echo "<option>$Customer_Company"; } echo "</select>"; ?> <br /> <input type="submit" name="button" id="button" value="Search by Customer Name" /></form> //Then I want to have it add to my html the Phone number and email on the same page below it.// Customer Phone Number: <?php echo "$Customer_Phone_Number" ?> Customer Email: <?php echo "$Customer_Email" ?> Quote Link to comment https://forums.phpfreaks.com/topic/141798-mysql-dynamic-drop-down-with-auto-populated-fields/ Share on other sites More sharing options...
krv Posted January 21, 2009 Share Posted January 21, 2009 JAVASCRIPT: <script language="JavaScript"> function change(){ var sel; var new_status; sel = document.getElementById('select'); for (i = 0; i < sel.options.length; i++) if (sel.options.selected) { new_value = sel.options.value; } if (new_value!=0){ window.location.href = 'example.php?id='+new_value; } } </script> PHP: USE THIS TO SELECT THE COMPANY <select onchange="change();" id="select"> <option value="0">SELECT COMPANY</option> <?php $query = "SELECT id,Customer_Company FROM via ORDER BY Customer_Company ASC"; $result = mysql_query($query) or die("Can't create query: " . mysql_error()); while ($row = mysql_fetch_assoc($result)) { // THIS SELECTS THE CUSTOMER NAME IN DROP DOWN AFTER IT HAS BEEN SUBMITTED. echo "<option value=\"$row[id]\""; if ($_GET['id'] == $row['id']) echo " selected=\"selected\""; echo ">$row[Customer_Company]</option>\n"; } ?> </select> RESULT PHP/HTML DISPLAY: <?php if (isset($_GET['id'])&&!is_numeric($_GET['id'])) { echo "Please select a customer."; } else { $sql = "SELECT * FROM via WHERE id='$_GET[id]'"; $result = mysql_query($result) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { echo " Customer Phone Number: $row[customer_number] <br /> Customer Email: $row[customer_email] "; } } ?> ?> MESS WITH THIS. Quote Link to comment https://forums.phpfreaks.com/topic/141798-mysql-dynamic-drop-down-with-auto-populated-fields/#findComment-742486 Share on other sites More sharing options...
fenway Posted January 27, 2009 Share Posted January 27, 2009 It's like no one's ever heard of code tags.... yeesh. Quote Link to comment https://forums.phpfreaks.com/topic/141798-mysql-dynamic-drop-down-with-auto-populated-fields/#findComment-747502 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.