Hey, I have a question regarding pulling information from a row in my database and displaying the results in my form,
I have a table called “products” which contains all the product information, in that table there is a row called “colors” the information in the this row is stored like so: 1;2;3;4;5;6 etc. These numbers, separated by semi-colon, are the id’s of the colors in the “colors” table.
In my form i have an area where you can select what colors the product comes in, by checking off the appropriate check box. This part so far is working and the data is being entered in the database properly, with the id’s being separated by colons. however when i go tot he “edit product” page these check boxes which id’s are in the table need to be checked off. This is where I’m having problems and i need help.
here is my code for the “edit products” page:
// get this stored info from the products table.
$sql = "SELECT * FROM products WHERE id='".$_GET['idr']."'";
$sql = mysql_query($sql);
$modify = mysql_fetch_array($sql);
// get the separated color id values from the products table, row "colors"
$var = explode (';',$modify['colors']);
foreach($var as $val)
{
$checkedcolor = $val;
}
//select all colors from the "colors" table
$colorsquery = mysql_query("SELECT * FROM colors");
while ($colors = mysql_fetch_array($colorsquery))
{
echo '<input type="checkbox" name="color" value="' . $colors['id'] . '">' . $colors['name'] . '<br />';
}