How could i create x amount of checkboxes based on how many items are in a database and populate each check box with a php variable containing the data from the database.
thanks.
How could i create x amount of checkboxes based on how many items are in a database and populate each check box with a php variable containing the data from the database.
thanks.
I have had a go and come up with the code below:
$sql1 = mysql_query("SELECT equipmentid, description FROM equipment") or die(mysql_error());
$row = mysql_fetch_assoc($sql1);
<?php for($i = "0"; i < strlen($row); $i++){ echo'<input type="checkbox" name="equipment" value="$row"/>';}?>
But i cant seem to get it to work.
The for loop is incorrect but you are better off using a while loop as much easier for what you require:
$sql1 = mysql_query("SELECT equipmentid, description FROM equipment") or die(mysql_error());
while ($row = mysql_fetch_assoc($sql1)) {
echo '<input type="checkbox" name="equipment" value="$row['equipmentid']"/>
}
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.