Jump to content

Archived

This topic is now archived and is closed to further replies.

xyn

SQL / PHP Arrays help.

Recommended Posts

Hi guys,
I have my private messenger inbox and I wanted my members to be-able to tick a box and delete that one ID so they can delete multiple messages at a time, Say if a member has 10 messages and wants to delete 6 at the same time, he ticks the 6 boxs and delets them all.

My problem is When i killed the Code and echod the array list It outputted 1 item out of the two i ticked. any ideas?

my code:
[code=php:0]<?PHP
include "Session.php";
$act = $_GET['act'];
if( !$act ){

include "db.php";
echo '<form method="post" action="?act=delete">';
$sql = mysql_query("SELECT id,sendto,sendfrom,subject FROM pm WHERE sendto='{$_SESSION['user']['user']}'");
while( $udat = @mysql_fetch_array($sql, MYSQL_NUM))
{
echo '<p>ID: '.$udat[0].'<br>To: '.$udat[1].'<br>From: '.$udat[2].'<br>Subject: '.$udat[3].'<br><input type="checkbox" name="del" value="'.$udat[0].'"></p>';
}
echo '<input type="submit" value="Delete"></form>';

} elseif( $act == delete ) {

if(isset($_POST['del']) && empty($_POST['del']))
{
echo "Please hylight the post you wish to delete.";
echo "<BR>";
echo "<a href=1test.php>Back</a>";
exit;
}

echo $_POST['del'];
exit;

$del[] = $_POST['del'];
if(is_array($del))
{
foreach($del as $key => $value)
{
$sql_delete = "".$value." , ";
}
include "db.php";
$db = mysql_connect("localhost", $login, $pwd);
mysql_select_db("zroxxco_members");

$dsql = "DELETE * FROM pm WHERE id='$sql_delete'";
mysql_query($dsql, $db);

echo "You have deleted messages #'.$sql_delete.'";
}
exit;
}
else
{
die('error: unknown location.');
}
?>[/code]

Share this post


Link to post
Share on other sites
$del[] = $_POST['del'];
if(is_array($del))
{

foreach($del as $key => $value)
{
$sql_delete = "".$value." , ";
}

Wont the array only itterate once, as $del would only contain $del[0] with the value of $_POST['del'] ?

Share this post


Link to post
Share on other sites
probably, thats what confusig me..

Share this post


Link to post
Share on other sites
Have your checkboxes named something like "del[]" and give each the value of te records id

[code]<input type='checkbox' name='del[]' value'$id' >[/code]

When you process the form data you can then delete them all with a single query with

[code]
$deleteList = join (',' , $_POST['del']);
mysql_query ("DELETE FROM tablename WHERE id IN ($deleteList)" );
?>[/code]

Share this post


Link to post
Share on other sites
Ah, thanks :]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.