[SOLVED] Passing multiple values via checkbox woes
Posted: Tue Jul 06, 2004 2:33 pm
Hello,
I am having a small problem I thought someone could comment on. I simply have a function which pulls a number of links from the database and displays them with a checkbox next to them. The ones that get checked will eventually get deleted...
You can see that the variable '$checkbox' is the relevant one. Now, I am attempting to pass the 'catid' of all the links that are checked by the user to another function which basically confirms the links checked and gives the user another chance to not delete them.
The problem is that I'm not sure how to display all the link names together. In other words when the 'delete_confirmation' function is called, I want to say...'are you sure you want to delete the following links?' and then have all the ones that were clicked listed below.
Here is a stripped down version of the confirmation function...
I can not get it to list all the links, just the last one checked. I don't understand why
doesn't work. I have to be missing something very easy, but I need a nudge in the right direction.
Thanks for any help
I am having a small problem I thought someone could comment on. I simply have a function which pulls a number of links from the database and displays them with a checkbox next to them. The ones that get checked will eventually get deleted...
Code: Select all
function display_edit_cat()
{
$sql = "SELECT * FROM link_cat order by catid asc";
$result = mysql_query($sql);
if(!$result)
{
echo("ERROR: " .mysql_error(). "\n$sql\n");
exit();
}
else
{
$ecf = "<p><center><table border=0 cellpadding=4>\n";
if(@mysql_num_rows($result) == 0)
{
genMsg('no_edit', 'Categories');
}
else
{
$row = mysql_fetch_array($result);
if($row)
{
$ecf .= '<form type=''get'' action=''admin_process.php''><input type=''hidden'' name=''action'' value=''delete_link_cat''>';
do
{
$linkname = $row["cat_name"];
$catid = $row["catid"];
$checkbox = '<input type="checkbox" name="catid[]" value="'. $catid .'"> '. $linkname;
$ecf .= $checkbox. '<br>';
}
while($row = mysql_fetch_array($result));
}
else
{
$ecf .= genMsg('general', 'Currently there are no categories.');
}
/*
while($myrow = mysql_fetch_array($result))
{
$linkname = $myrow["cat_name"];
$catid = $myrow["catid"];
$ecf .=
"<tr><td class=medium>$linkname</td>\n<td><A HREF="admin_forms.php?catid=$catid">Edit</a></td>
<td><A HREF="admin_process.php?catid=$catid&action=delete_link_cat">Delete</a></td>
</tr>";
}
//$ecf .= "</table></td></tr></table></td><td align=center valign=top>";
*/
$ecf .= "<input type="submit" name="submit" value="Submit"><input type="reset" value="Reset"></form></table></td></tr></table></center> ";
}
}
return $ecf;
}The problem is that I'm not sure how to display all the link names together. In other words when the 'delete_confirmation' function is called, I want to say...'are you sure you want to delete the following links?' and then have all the ones that were clicked listed below.
Here is a stripped down version of the confirmation function...
Code: Select all
function admin_delete_confirm($id, $type) <--$id is catid passed from other function
{
if($type == 'link_cat')
{
foreach($id as $catid)
{
$sql = "SELECT cat_name FROM link_cat WHERE catid=" .$catid;
}
$result = mysql_query($sql);
if(!$result)
{
$addel = genMsg('sql', '');
}
else
{
//while($row = mysql_fetch_array($result))
//{
//$catname = $row["cat_name"];
//echo $catname. '<br>';
//}
//$addel .= 'Are you sure you want to delete the category - ' .$catname. '?<p>';
//$addel .= '<a href=admin_forms.php?action=admin_delete&var=link_cat&id=' .$id. '>Yes, delete</A>';
}
}
return $addel;
}Code: Select all
while($row = mysql_fetch_array($result))
{
$catname = $row["cat_name"];
echo $catname. '<br>';
}Thanks for any help