mardi 15 septembre 2015

Dynamically check dynamic checkboxes from MySQL in PHP

I have some dynamically created checkboxes, creating using this bit of PHP:

<?php do { ?>
<input type="checkbox" name="Cat_Ref_Array[]" value="<?php echo $row_selectCategories['Cat_Ref']; ?>" />
<label for="Category"><?php echo $row_selectCategories['Category']; ?></label>
<?php } while ($row_selectCategories = mysql_fetch_assoc($selectCategories)); ?>

I also have a another table with possible responses saved, which is retrieved like so:

$query_getFeatureCat = sprintf("SELECT `Ref`, Cat_Ref, dist FROM newtable WHERE `Ref` = %s", GetSQLValueString($colname_getFeatureCat, "text"));
$getFeatureCat = mysql_query($query_getFeatureCat, $db) or die(mysql_error());
$row_getFeatureCat = mysql_fetch_assoc($getFeatureCat);

How can I get the form to prepopulate/"check" the checkboxes when the checkbox value appears in the output from the newtable lookup?




Aucun commentaire:

Enregistrer un commentaire