Jump to content

Input boxes from a database


xionhack

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.