Click to See Complete Forum and Search --> : Using variables as checkbox values


foxache
01-29-2004, 05:01 AM
Hi. I'm still slugging along with the same old things, but here's a quicky.

Why doesn't this work????

<?
$query = mysql_query("SELECT * FROM $tb ORDER BY category ASC");
while ($name = mysql_fetch_array($query)) {
print "<div align=\"left\">
<input type=\"checkbox\" name=\"delete\" value=\"$name\">";
print $name['table'];
}
?>

What it should do is output a list of categories with checkboxes. Each checkbox is an option to delete that category. So the name is "delete" and the value should be the category name. Then when submitted the script will delete it from the table. I couldn't work out why it wasn't deleting anything until I realised the problem was that the value of the checkbox allways returns as "Array" when I viewed the source, and not the name of the category...

Anyone?

Thanks.

piersk
01-29-2004, 05:20 AM
Originally posted by foxache

<?
$query = mysql_query("SELECT * FROM $tb ORDER BY category ASC");
while ($name = mysql_fetch_array($query)) {
print "<div align=\"left\">
<input type=\"checkbox\" name=\"delete\" value=\"$name\">";
print $name['table'];
}
?>



Try this instead: $query = mysql_query("SELECT value FROM $tb ORDER BY category ASC");
$result = mysql_query($query,$connectionstring);
while($name=mysql_fetch_array($query))
{
print "<div align=\"left\">
<input type=\"checkbox\" name=\"delete\" value=\"$name['value']\">";
print $name['table'];
?>

foxache
01-29-2004, 05:41 AM
Hmmmm.
When putting ['value'] after $name, the page browser doeesn't output anything...

piersk
01-29-2004, 05:43 AM
Ok, I have no idea what your db looks like, so the "value" is the name of the column that stores the value. Change it to whatever it should be.

foxache
01-29-2004, 05:49 AM
Oh sorry, <blushes> stupid me.
Thanks

foxache
01-29-2004, 05:55 AM
Ah ha!

Tried and works, though with a couple of adjustments. I had to put the $name['category'] on a new row with a new PRINT command.

Thanks V. Much.