I have a problem to solve which im not sure if it can be solved in the way that i have in mind. It's about a form with checkboxes. The purpose of this form is to allow users to add or remove their favorite brands from the database by checking/unchecking the form checkboxes. The challege that i face now is that there may already be brands selected in the past from the user. And i would like the page when it loads to check in the database and automatically check the brands in the form which where found in the database. I checked to see if it was possible with jquery , but i got stuck. Here is my code:
/* == SQL CODE == */
CREATE TABLE IF NOT EXISTS `favoriteBrands` (
`pkFavoriteBrand` int(5) NOT NULL AUTO_INCREMENT,
`fkCompanyID` int(5) NOT NULL,
`Brands` varchar(30) NOT NULL,
PRIMARY KEY (`pkFavorietemerken`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=81 ;
INSERT INTO `favoriteBrands` (`pkFavoriteBrand`, `fkCompanyID`, `Brands`) VALUES
(80, 7, 'Replay'),
(79, 7, 'Pepe Jeans'),
(71, 12, 'Nike'),
(70, 12, 'Le Coq Sportif'),
/* == SQL CODE == */
/* == PHP CODE == */
<?php
$find_fav_brands = " SELECT Brands FROM favoriteBrands WHERE fkCompanyID=$company_id";
$get_brand = mysql_query($find_fav_brands) or die ("No brand found");
while($row = mysql_fetch_assoc($get_brand )){
$show_brand = $row["Brands"];
echo"<p>$show_brand</p>";
}?>
<form name="form" method="post" action="ready.php" >
<ul>
<li><input type="checkbox" name="merk[]" value="Adidas"/>Adidas</li>
<li><input type="checkbox" name="merk[]" value="Airforce"/>Airforce</li>
<li><input type="checkbox" name="merk[]" value="Armani"/>Armani</li>
<li><input type="checkbox" name="merk[]" value="Asics"/>Asics</li>
</ul>
</form>
/* == PHP CODE == */