PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Jim_Bo
Forum Contributor
Posts: 390 Joined: Sat Oct 02, 2004 3:04 pm
Post
by Jim_Bo » Mon Feb 21, 2005 8:07 pm
Hi,
I have setup a checkbox system where you can select all .. bu when you use the delete button .. nothing gets deleted?
here are parts of the code I guess are of relevance:
Code: Select all
echo "<form name="form" method="post" action="../index.php?pages=pmparse&id=$id&cmd=deleterecord">
<table width="95%" border="0" cellspacing="1" cellpadding="5">
<tr>
<td bgcolor="#FEB341" width="7%"><div align="center"><font class="txt"><input type="submit" name="Submit" value="Delete"><input type="checkbox" value="on" name="allbox" onclick="checkAll();"/></font></div></td>
<td bgcolor="#FEB341" width="15%"><div align="center"><font class="txt">SENDER</font></div></td>
<td bgcolor="#FEB341" width="49%"><div align="center"><font class="txt">SUBJECT</font></div></td>
<td bgcolor="#FEB341" width="20%"><div align="center"><font class="txt">DATE</font></div></td>
<td bgcolor="#FEB341" width="10%"><div align="center"><font class="txt">READ</font></div></td>";
// Define colors for the alternating rows
$color1 = "#CCCCCC";
$color2 = "#999999";
Code: Select all
echo "<tr>
<td width="7%" bgcolor="$row_color"><div align="center"><font class="txt"><a href="../index.php?pages=pmparse&id=$id&cmd=deleterecord">Delete</a> <input type="checkbox" value="$id" name="$id"></font></div></td>
<td width="15%" bgcolor="$row_color"><font class="txt">$sender</font></td>
<td width="49%" bgcolor="$row_color"><font class="txt">$subject</font></td>
<td width="20%" bgcolor="$row_color"><div align="center"><font class="txt">$date</font></div></td>
<td width="10%" bgcolor="$row_color"><div align="center"><font class="txt"><a href="../index.php?pages=read&id=$id">Read $read</a></font></div></td>
</tr>";
// Add 1 to the row count
$row_count++;
}
// Close out your table.
echo "</table></form>
<br>";
Hows does it reference to all the id's of the checked options ..?
I can delete a single record fine using the text "delete" option you can see in the loop above ..
Thanks
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Feb 21, 2005 8:15 pm
rename all the checkboxes to id[].
then expect an array of id's that were checked to delete..
Jim_Bo
Forum Contributor
Posts: 390 Joined: Sat Oct 02, 2004 3:04 pm
Post
by Jim_Bo » Mon Feb 21, 2005 8:32 pm
Hi,
Not quite with you I guess ..
javascript:
Code: Select all
<script language="javascript">
function checkAll(){
for (var i=0;i<document.formsї0].elements.length;i++)
{
var e=document.formsї0].elementsїi];
if ((e.name != 'allbox') && (e.type=='checkbox'))
{
e.checked=document.formsї0].allbox.checked;
}
}
}
</script>
The main check box ( out of the loop ):
[code<form name=\"form\" method=\"post\" action=\"../index.php?pages=pmparse&id=$id&cmd=deleterecord\">
<input type=\"submit\" name=\"Submit\" value=\"Delete\">
<input type=\"checkbox\" value=\"on\" name=\"allbox\" onclick=\"checkAll();\"/>
Checkbox within the loop:
Code: Select all
<input type="checkbox" value="$id" name="idї]">
Something like that? .. Altho it doesnt work ..
Thanks
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Feb 21, 2005 9:25 pm
did you alter the script to know how to process an array when it recieves it?
Jim_Bo
Forum Contributor
Posts: 390 Joined: Sat Oct 02, 2004 3:04 pm
Post
by Jim_Bo » Mon Feb 21, 2005 10:01 pm
Hi,
I have now .. All working great now .. Wasnt sure on the array part ..
Thanks ..
Jim_Bo
Forum Contributor
Posts: 390 Joined: Sat Oct 02, 2004 3:04 pm
Post
by Jim_Bo » Mon Feb 21, 2005 10:07 pm
Hi,
Here are the basics of it for others who want the same situation ..
Javascript:
Code: Select all
<script language="javascript">
function checkAll(){
for (var i=0;i<document.formsї0].elements.length;i++)
{
var e=document.formsї0].elementsїi];
if ((e.name != 'allbox') && (e.type=='checkbox'))
{
e.checked=document.formsї0].allbox.checked;
}
}
}
</script>
Data:
Code: Select all
<form name="form" method="post" action="../path to delete script">
<input type="submit" name="Submit" value="Delete">
<input type="checkbox" value="on" name="allbox" onclick="checkAll();"/>
<input type="checkbox" value="$id" name="idї]">
</form>
Delete Script:
Code: Select all
foreach ($_POSTї'id'] as $id)
{
$sql = mysql_query("DELETE FROM pm WHERE id = $id") or die (mysql_error());
if(!$sql){
echo ("<center>There has been an error deleting this email. Please contact the webmaster.</center>");
}
echo "<br><center>Record deleted</center><br>";
Good Luck