nec9716 Posted March 20, 2008 Share Posted March 20, 2008 //Get driver1 post information. if(isset($_POST['DropDown1'])) $driver1 = $_POST['DropDown1']; else $driver1 = 1; //Generate and run the query to populate the driver1 listbox. (driver1) $query = "SELECT id, name FROM pilote"; $result = mysql_query($query); //--Create 1 listbox. echo '<b>Driver # 1:</b><br/>'; echo '<select name="driver1" size="1" onchange="setItemListBox()">'; while($row = mysql_fetch_array($result, MYSQL_NUM)) { if($row[0] == $driver1) echo '<option value="' . $row[0] . '" selected>' . $row[1] . '</option>'; else echo '<option value="' . $row[0] . '">' . $row[1] . '</option>'; } echo '</select>'; //--End 1 listbox when I select something from the list box the ID is ( which is my first column ) is write in the DB but I want to write what I'm select ( in this case ) my second column of my DB? I can't understand what I have to change in this script to allow me to do so thank you Link to comment https://forums.phpfreaks.com/topic/97089-record-id-instead-of-data/ Share on other sites More sharing options...
BlueSkyIS Posted March 20, 2008 Share Posted March 20, 2008 it's better to store the id, but if you want the string value instead, replace option value="' . $row[0] . '" selected> with this: option value="' . $row[1] . '" selected> Link to comment https://forums.phpfreaks.com/topic/97089-record-id-instead-of-data/#findComment-496780 Share on other sites More sharing options...
nec9716 Posted March 20, 2008 Author Share Posted March 20, 2008 why it's better to store ID? thank for your correction Link to comment https://forums.phpfreaks.com/topic/97089-record-id-instead-of-data/#findComment-496783 Share on other sites More sharing options...
BlueSkyIS Posted March 20, 2008 Share Posted March 20, 2008 because it is a unique identifier for the record. you should try to compare integers instead of strings whenever possible. also, storing the id allows you to change the value of the string in one place without having to change it in every record. also, storing the id of the record takes less space. i'm sure there's more. it's just standard database procedure/normalization. Link to comment https://forums.phpfreaks.com/topic/97089-record-id-instead-of-data/#findComment-496843 Share on other sites More sharing options...
nec9716 Posted March 20, 2008 Author Share Posted March 20, 2008 ok ...i think be able to remember that thank for the advise Link to comment https://forums.phpfreaks.com/topic/97089-record-id-instead-of-data/#findComment-496854 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.