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. I have had a go and come up with the code below: But i cant seem to get it to work.

$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"/>';}?>

Check the following link to know more about how mysql_fetch_assoc() works.
http://in2.php.net/manual/en/function.mysql-fetch-assoc.php

$sql1 = mysql_query("SELECT equipmentid, description FROM equipment") or die(mysql_error());
//$numberofrows = mysql_num_rows($sql1); Not necessary in this case, but for you to know how to fetch the number of records returned.

while($row = mysql_fetch_assoc($sql1)) {
    echo '<input type="checkbox" name="equipment[]" value="'.$row['equipmentid'].'"/>'.$row['description']."<br />";
}

Hope this helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.