tawevolution Posted November 1, 2006 Share Posted November 1, 2006 Hey. Currently I have an 'add' for which has a drop down list of 3 languages, which when submitted is added to a database (this bit works). What I want to do is have an 'edit' form which looks at the database, sees what language it is, and then automatically selects the right language in the drop down box automatically. at the moment my edit form has the drop down box (like the add) but next to it i have to have text saying what it WAS.hope this is explained well, cus i easily confuse myself and others xDevo Link to comment https://forums.phpfreaks.com/topic/25838-drop-down-list-being-selected-from-a-database/ Share on other sites More sharing options...
craygo Posted November 1, 2006 Share Posted November 1, 2006 OK you have an sql selecting your data. I do not know what your table structure is like so I will say the langues field is called "language"[code]<?php// Select date from database$sql = "SELECT * FROM table WHERE id = '$id'"; $res = mysql_query($sql) or die (mysql_error()); $r = mysql_fetch_assoc($res);// create language array$lang = array("English", "French", "Italian");// start dropdown manuecho "<select name=lang>";// Loop through language array foreach($lang as $language){ if($language = $r['language']){ echo "<option value=\"$language\" selected>$language</option>"; } else { echo "<option value=\"$language\">$language</option>"; } } echo "</select>";?>[/code]Ray Link to comment https://forums.phpfreaks.com/topic/25838-drop-down-list-being-selected-from-a-database/#findComment-118032 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.