Page 2 of 2

Posted: Sun Jul 23, 2006 5:57 pm
by infolock
for ($i = 0; $i < $searchtermscount; $++)

should be

for ($i = 0; $i < $searchtermscount; $i++)

Posted: Sun Jul 23, 2006 5:58 pm
by blade_922
yeh i edited my post when i realised that, check back on the last post on first page.

Posted: Sun Jul 23, 2006 6:05 pm
by infolock
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;
?>

Posted: Sun Jul 23, 2006 6:11 pm
by blade_922
hey ok i tried that n it didnt delete the comments that time either.

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; 
?>
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

Posted: Sun Jul 23, 2006 6:21 pm
by John Cartwright
you did remember to pass your query through mysql_query() right?

Posted: Sun Jul 23, 2006 6:25 pm
by blade_922
uumm, im not sure. Im kinda not to familiar to php n mysql yet, so if ya can show me how exactly i would do that, that would be great. :) thanks

Posted: Sun Jul 23, 2006 6:43 pm
by MarK (CZ)

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);

?>

Posted: Sun Jul 23, 2006 6:48 pm
by blade_922
Ok hey thanks alot. Thatsworking,

That deletes out the comment in the comment field, but not the entire comment row. How can i make it delete the entire comment, like i began off to do.

Posted: Sun Jul 23, 2006 6:56 pm
by MarK (CZ)

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);

?>
Just use DELETE FROM instead of UPDATE ;)

Posted: Sun Jul 23, 2006 7:02 pm
by blade_922
cheers man thanks alot, ive been tryin to solve this 4 days. Im up here itill 1am doing this lol. Thanks again.

Posted: Mon Jul 24, 2006 1:07 am
by MarK (CZ)
I've been writing the reply around 2am.. php is addictive 8O :P