karl_009 Posted February 27, 2009 Share Posted February 27, 2009 Hello, I have a from and I have been able to set it up so the list/menu adds and updates the data in the database, but it always shows the menu as blank on the edit page. How would I go about getting the current record in the database to be shown in that list menu when I come to edit it? Here is the List/Menu Code HTML; <select id="country" name="country" class="field select addr" tabindex="11" value="<?php echo $rows['country']; ?>"> <option value="" selected="selected"></option> <option value="United Kingdom">United Kingdom</option> <option value="Australia">Australia</option> <option value="Austria">Austria</option> <option value="Belgium">Belgium</option> <option value="China">China</option> <option value="Egypt">Egypt</option> <option value="Finland">Finland</option> <option value="France">France</option> <option value="Germany">Germany</option> <option value="Greece">Greece</option> <option value="Hong Kong">Hong Kong</option> <option value="Hungary">Hungary</option> <option value="Iceland">Iceland</option> <option value="India">India</option> <option value="Ireland">Ireland</option> <option value="Italy">Italy</option> <option value="Norway">Norway</option> <option value="Poland">Poland</option> <option value="Russia">Russia</option> <option value="United States">United States</option> </select> An here is the PHP code that is on the page; <?php require ($_SERVER['DOCUMENT_ROOT']."cmstesting/config/db_config.php"); $connection = @mysql_connect ($db_host, $db_user, $db_pass) or die ("Error with Connection"); mysql_select_db ($db_name, $connection); // Get value from address bar $conid=$_GET['conid']; // Get data from database $query = "SELECT * FROM contacts WHERE conid='$conid'"; $result = mysql_query ($query); $rows = mysql_fetch_array ($result); ?> Many Thanks for any help... Karl Quote Link to comment https://forums.phpfreaks.com/topic/147219-solved-display-data-from-database-in-listmenu/ Share on other sites More sharing options...
Stephen68 Posted February 27, 2009 Share Posted February 27, 2009 How are they stored in the database? Do you allow more then one selection? if it's only one maybe do something like //Make array of all the countries $country = ("United Kingdom","Australia",Belgium",.... ect) //Get the country that is in the DB for the user $rows = mysql_fetch_array ($result); $userCountry = $row['$conid']; //Now loop through array and display as HTML while using in_array to make their country selected //Get number of items in array $countryCount = count($country); for ($i=0; $i<=$countryCount;$i++ ) { if(in_array($userCountry, $country)) { //This is the users country to set it to select echo "<option value='".$country[$i]".' selected>".$country[$i]."</option>"; }else{ //Country is not in array so just display normal select <option value='".$country[$i]."'>".$country[$i]."</option>"; } } This is just off the top of my head hope it helps some Quote Link to comment https://forums.phpfreaks.com/topic/147219-solved-display-data-from-database-in-listmenu/#findComment-772855 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.