xionhack Posted November 11, 2008 Share Posted November 11, 2008 Hello. I need help with something I am doing. Lets say that I have to tables "member" and "color", the "member" has "member_id, first_name, last_name" the "color" table has "color_id, color". What I want is to call all the members that dont have a color assigned, and next each name a select box with all the colors, and when they select one and press a button the "color" field in the "member" table will be updated with the color selected for that particular member. Please let me know if you understand! thanks! Link to comment https://forums.phpfreaks.com/topic/132240-input-boxes-from-a-database/ Share on other sites More sharing options...
bobbinsbro Posted November 11, 2008 Share Posted November 11, 2008 you mean something like this? <?php $sql = "SELECT * FROM color"; $result = mysql_query($sql); $selectColor = "<select name='selectColor'>"; while ($color = mysql_fetch_array($result)){ $selectColor .= "<option value='".$color['color_id']."'>".$color['color']."</option>"; } $selectColor .= "</select>"; unset($result, $color); $sql = "SELECT * FROM member WHERE color IS NULL"; $result = mysql_query($sql); while ($row = mysql_fetch_array($result)){ echo $row['first_name'], " ", $row['last_name'], ": ", $selectColor, "<br />"; } ?> note: this is not working code! no mysql_connect(), no form creation. edit it to suit your needs. Link to comment https://forums.phpfreaks.com/topic/132240-input-boxes-from-a-database/#findComment-687540 Share on other sites More sharing options...
radalin Posted November 11, 2008 Share Posted November 11, 2008 some addition to bobbinsbro's code, you should also be sure that color's default value is null. It might cause problems if you have empty string in color fields. Link to comment https://forums.phpfreaks.com/topic/132240-input-boxes-from-a-database/#findComment-687580 Share on other sites More sharing options...
bobbinsbro Posted November 11, 2008 Share Posted November 11, 2008 oops, you're right. this should be better: $sql = "SELECT * FROM member WHERE color='' OR color IS NULL"; Link to comment https://forums.phpfreaks.com/topic/132240-input-boxes-from-a-database/#findComment-687587 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.