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! Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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"; Quote Link to comment 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.