0

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"/>';}?>
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by as.bhanuprakash
1

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.