Hi,
I am creating a HTML form dynamically from a db using checkboxes like this:
$sql = "SELECT * FROM table;";
$result = mysql_query( $sql );
while ($a_row = mysql_fetch_array($result) ) {
print "<input type='checkbox' name='Num$a_row[id]' value='$a_row[name]'>";
}
This works fine, and I get checkboxes with names like Num1,Num2,Num3 etc. 🙂
What I want to do now is add some functionality when the page is submitted.
I want to loop through the same table again, and for each entry work out wether the checkbox is checked, and if so - do an insert into another table. e.g.
$sql = "SELECT * FROM table;";
$result = mysql_query( $sql );
while ($a_row = mysql_fetch_array($result) ) {
if($Num$a_row[id] == "on"){
//Do insert
}
Now this doesn't work obviously because '$Num$a_row[id]' is not the same as $Num1. So how can i append the value of $a_row[id] to $Num so I have a new variable $Num1 which I can use to find out if it is checked or not?
Is there an easier way of doing this?
Thanks,
Jay