while loop deleting fields? help!! :)
Moderator: General Moderators
try this...
Code: Select all
<?php
/**
* Replace the terms in this array with the terms inside the comments you want to remove
*/
$searchterms = array('pharmacy', 'snots', 'booty', 'stinkbug', 'snaggletooth', 'footsmell', 'buttscratch', 'stupiduserentry');
$sql = "UPDATE `mos_akocomment` SET `comment` = '' WHERE 1=1";
foreach($searchterms as $key => $value) {
$sql .= " OR `comment` LIKE '%$value%'";
}
echo $sql;
?>hey ok i tried that n it didnt delete the comments that time either.
I tried it n didnt delete the comments, lol what did i get myself into, i thought php mysql was easy(ive got alot of learning to do) :p
So dya know anything else i can try
Code: Select all
<?php
/**
* Replace the terms in this array with the terms inside the comments you want to remove
*/
$searchterms = array('pharmacy', 'snots', 'booty', 'stinkbug', 'snaggletooth', 'footsmell', 'buttscratch', 'stupiduserentry');
$sql = "UPDATE `mos_akocomment` SET `comment` = '' WHERE 1=1";
foreach($searchterms as $key => $value) {
$sql .= " OR `comment` LIKE '%{$value}%'";
}
echo $sql;
?>So dya know anything else i can try
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
you did remember to pass your query through mysql_query() right?
- MarK (CZ)
- Forum Contributor
- Posts: 239
- Joined: Tue Apr 13, 2004 12:51 am
- Location: Prague (CZ) / Vienna (A)
- Contact:
Code: Select all
<?php
/**
* Replace the terms in this array with the terms inside the comments you want to remove
*/
$searchterms = array('pharmacy', 'snots', 'booty', 'stinkbug', 'snaggletooth', 'footsmell', 'buttscratch', 'stupiduserentry');
$conditions = array();
foreach($searchterms as $value)
$conditions[] = "`comment` LIKE '%{$value}%'";
$sql = "UPDATE `mos_akocomment` SET `comment` = '' WHERE ".implode(" OR ", $conditions);
//
// connect to the db server and select db
//
$result = mysql_query($sql);
?>- MarK (CZ)
- Forum Contributor
- Posts: 239
- Joined: Tue Apr 13, 2004 12:51 am
- Location: Prague (CZ) / Vienna (A)
- Contact:
Code: Select all
<?php
/**
* Replace the terms in this array with the terms inside the comments you want to remove
*/
$searchterms = array('pharmacy', 'snots', 'booty', 'stinkbug', 'snaggletooth', 'footsmell', 'buttscratch', 'stupiduserentry');
$conditions = array();
foreach($searchterms as $value)
$conditions[] = "`comment` LIKE '%{$value}%'";
$sql = "DELETE FROM `mos_akocomment` WHERE ".implode(" OR ", $conditions);
//
// connect to the db server and select db
//
$result = mysql_query($sql);
?>