Forum Moderators: coopster

Message Too Old, No Replies

How do I mass delete entries with a certain value in a...

How do I mass delete entries with a certain value in a particular column?

         

phpsqlprogrammer

5:15 pm on Dec 19, 2003 (gmt 0)

10+ Year Member



How do I mass delete entries with a certain value in a particular column?

Hi, thanks for answering in advance.

How do I mass delete all entries that has a value, say 123.123.com under the column "remotehost" in a table? Any SQL query that fits my description?

You see, this is a counter script and I am trying to remove all the counts that belong to me.

Thanks. :]

coopster

5:27 pm on Dec 19, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, phpsqlprogrammer!

DELETE FROM table WHERE remotehost = '123.123.com'

phpsqlprogrammer

5:50 pm on Dec 19, 2003 (gmt 0)

10+ Year Member



Thank you so much! Now, I do not have to manually delete the entries one by one! ;)

Thanks, coopster!

henry0

10:31 pm on Dec 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I use that, you can adapt it to your needs
<<<
<?

function db_connect()
{
$result = @mysql_pconnect("aaaaa", "bbbbb", "cccccc");
if (!$result)
return false;
if (!@mysql_select_db("dddddddd"))
return false;

return $result;
}
?>

<?php
$conn = db_connect();
?>

<?php

$query="delete FROM articles where adate between '$date_start' and '$date_end' and sectionID='$section_id'";
$result= mysql_query ($query);

?>

then do a simple form to pass value

phpsqlprogrammer

8:07 am on Dec 20, 2003 (gmt 0)

10+ Year Member



Hello, Henry0, thanks for replying. I hope you do not mind my following questions.

1. What are aaa bbb ccc ddd supposed to represent?
2. "then do a simple form to pass value" What do you mean by pass value? Do you mean like "echo $result"?

Thanks for replying!

P.s. I do not know what are $result and $conn for, but I will read the help files to understand.

henry0

12:34 pm on Dec 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



HEllo
AAA, BBB, CCC are the database:

host name such as localhost or whatever your db host has provided you with.

your username

your password

DDDD stands for the table name

here is the form I use along the above script which is named
del.php
look at the variable $..something of the form
they store the data you want to pass to your php script.

hope it helps
as is you may change the form fields, change in accordance the del.php script

add your own DB server data (A, B, C, D)
and you'll be in business

you may see that I use a beginning date and an ending date
plus a section id
of course feel free to change it all to your like

just be aware that I did not include any warning or security
against oneself
weight your typing options, when you will clik on the form
your decision is final
there is no way back
so first add a few data that you don't care about
and see how the delete reacts

also i ALWAYS DO A FRESH DB BACKUP
BEFORE ANY DELETTE SESSION

CHEERS

Henry

<html>
<head>
<title>Del from Articles</title>
</head>
<body bgcolor="ffffcc">
<table width="650" border="5" align="middle" valign="top">
<tr>
<td width="640" align="left" valign="top">
<h4> Admin only- Delete from Articles<br>
ORDER: Year, Month and Day</h4>
<p>
<form action ="del.php" method="post">
Enter date_start:<input type="text"name="date_start" value="<?php echo $date_start;?>">
<p>
Enter date_end:<input type="text"name="date_end" value="<?php echo $date_end;?>">
<p> <!-- // following are the section ID -->
<b>4=Round-up; 5=Roundup Archives<br>
6=Business; 7= Business Archives<br>
8=Business People; 9= Business People Archives<br>
10=Events; 11= Events Archives<p>

Enter section_id:<input type="text"name="section_id" value="<?php echo $section_id;?>">
<p>

<br>
<input type="submit"></form>
</tr></td>

</table>
</body>
</html>

phpsqlprogrammer

2:15 am on Dec 21, 2003 (gmt 0)

10+ Year Member



Thanks henry0!

Your scripts have saved me a lot of trouble. Thank you very much. MySQL is indeed very flexible! :)

henry0

11:44 am on Dec 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



you're indeed welcome
cheers

Henry