Dynamic checkboxes/labels from Db
Posted: Fri Jan 19, 2007 6:03 pm
feyd | Please use
I have three records in the table, and all this code outputs is a single checkbox w/o any label(s).
PLEASE HELP!
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I'm having trouble figuring out how to make a form that will create a dynamic number of checkboxes. I want to pull all records from a table and dynamically create a corresponding number of checkboxes on the form page. This will enable the user to add additional records to the table without ever manually coding another checkbox. Here's what I have (this code is within a form and <td> tag:Code: Select all
<?
mysql_connect($hostname,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM genre";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$desc=mysql_result($result,$i,"desc");
?>
<input type="checkbox" name="cBox[]" value="1"/><? echo $desc; ?> <br>
<?
$i++;
}
?>PLEASE HELP!
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]