Jump to content

SQL / PHP Arrays help.


xyn

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]
Link to comment
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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.