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
dwfait
Forum Contributor
Posts: 113 Joined: Sun Aug 01, 2004 10:36 pm
Post
by dwfait » Fri Aug 13, 2004 1:03 pm
I have a checkbox for each Private Message on a page. Their on a form. How would i make it so that it gets all of the name of all of the checkboxes, which the names of would be the ID of the PM's in the database, and then delete that row from the table?
Here is the code that makes the checkbox for each provate message:
Code: Select all
echo "
<form method="POST" action="index.php?action=msgcsrd">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1">
<tr>
<td width="20%" align="center">From:</td>
<td width="20%" align="center">Subject:</td>
<td width="20%" align="center">Date:</td>
</tr>
";
$link = mysql_connect("localhost", "root", "")
or die("Could not connect");
mysql_select_db("stormst_sspp")
or exit("Could not select database");
$query = mysql_query("SELECT * FROM pm WHERE toid='$suser' ORDER BY `ID` DESC") or die(mysql_error());
$pmc='0';
while($row = mysql_fetch_assoc($query)) {
$pmc++;
$fromid=$row['fromid'];
$subject=$row['subject'];
$date=$row['date'];
$id=$row['id'];
echo "
<tr>
<td width="20%">
<p align="center">
<input type="checkbox" name="C$id" value="ON" style="float: left">$fromid</td>
<td width="20%">
<p align="center"><a href="index.php?action=msgcrf&id=$id">$subject</a></td>
<td width="20%">
<p align="center">$date</td>
</tr>";
}
echo "
</table>
";
if ($pmc=='0') {
Echo "You have no private messages.";
} else {
echo "
<input type="submit" value="Delete Selected Items" name="B1">";
}
echo " </form>";
mysql_close($link);
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Aug 13, 2004 1:30 pm
you could switch the name to something like:
then just foreach the $_POST['delete_pm'] for each key
dwfait
Forum Contributor
Posts: 113 Joined: Sun Aug 01, 2004 10:36 pm
Post
by dwfait » Sat Aug 14, 2004 4:35 am
Thanks, but i am a complete noob and wouldnt know how to get the variable of the array in the loop..
m3mn0n
PHP Evangelist
Posts: 3548 Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada
Post
by m3mn0n » Sat Aug 14, 2004 7:08 am
Have a look at [php_man]foreach[/php_man]().
dwfait
Forum Contributor
Posts: 113 Joined: Sun Aug 01, 2004 10:36 pm
Post
by dwfait » Sat Aug 14, 2004 8:13 am
With the for statement:
Code: Select all
foreach ($_POST['delete_pm'] as $value) {
echo "$value";
}
It just displays the status of the checkbox. How would i get $id value out of it so i can find that row in the table?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Aug 14, 2004 9:59 am
Code: Select all
foreach($_POST['delete_pm'] as $k => $v)
echo $k."\n";
dwfait
Forum Contributor
Posts: 113 Joined: Sun Aug 01, 2004 10:36 pm
Post
by dwfait » Sat Aug 14, 2004 11:04 am
Thanks feyd
.