It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming PHP and MySQL Forum

Massive records delete, PHP+MySQL

Moderator: Malcolm

Massive records delete, PHP+MySQL

Postby Nothing2Lose on Sat May 07, 2005 4:47 am

hi,

I know how to delete records from MySQL (one-by-one), but i dont know how to do it at once.

how can I delete group of records at once (one button push), I want to choose the reocords by the CheckBoxes. plz check this illu for more info :)
I want to do same Hotmail.

regards.
Last edited by Nothing2Lose on Tue May 10, 2005 8:12 am, edited 1 time in total.
Nothing2Lose
 
Posts: 28
Joined: Fri Apr 08, 2005 7:26 am

Postby webmaster on Sat May 07, 2005 9:08 am

When you loop out the rows with Sender, Subject and stuff, you also loop out a checkbox with individual IDs.

On the next page you check:
Code: Select all
if(isset($_POST['id1'])) {

   $postid = $_POST['id1'];
   DELETE FROM posts WHERE postid='$postid'
}


Then you can do an array or a loop for that, or just copy the code 30 times and change the numbers. (if you list 30 results / page)

To send over the postid, set the postid as VALUE in the checkbox.

I haven't done something like this before, but I think it'll work.
Make sure to check out our TNX Review and Link Vault Review
User avatar
webmaster
Site Admin
 
Posts: 2695
Joined: Tue Aug 17, 2004 1:07 pm
Location: Sweden

Postby Nothing2Lose on Sun May 08, 2005 1:15 am

hi,

webmaster your code doesnt work, I have this code it shows the mysql records with checkbox on side, but it doesnt delete the record, can any help help with this code?

Code: Select all
$result = mysql_query(" select  *  from Table ");

$checkbox = $_POST['checkbox'];
echo "<form action=index.php method=$_POST['checkbox']>";

while($res=mysql_fetch_array($result))
{
$UserName = $res["UserName"];
echo "<input type=checkbox name = 'del[]' value = $UserName>";
echo "$UserName<br>";
}

echo "<input name=Submit type=submit>";
echo "</form>";

if (count($del) > 1) {
for ($i=0;$i<count($del);$i++) {
$result[$i] = mysql_query("DELETE FROM Table WHERE UserName = '$del[$i]'");
}

echo "Record deleted!";
}
Nothing2Lose
 
Posts: 28
Joined: Fri Apr 08, 2005 7:26 am


Who is online

Users browsing this forum: No registered users and 0 guests