Jump to content
MakeWebGames

Clean a shout box


Recommended Posts

It supposed to delete shout_box messages but it doesn't

If you can help me i greatly appreciate it

error is

QUERY ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-14' at line 1
Query was SELECT `id` FROM `shout_box` ORDER BY `id` ASC LIMIT -14;

 

<?php
include_once(DIRNAME(__FILE__) .'/globals.php'):
$count = 0;
$num = $db->fetch_row($db->query("SELECT COUNT(`id`) as `numb` FROM `shout_box`;"));
$amount = $num['numb']-15;
$chats = $db->query("SELECT `id` FROM `shout_box` ORDER BY `id` ASC LIMIT ". $amount .";");
while($chat = $db->fetch_row($chats)) {
	$db->query("DELETE FROM `shout_box` WHERE (`id` = ". $chat['id'] ."):");
		$count++;
}
echo $count.' rows deleted.';
?>

 

the SQL for shout box is

[mysql]CREATE TABLE IF NOT EXISTS `shout_box` (

`id` int(11) NOT NULL auto_increment,

`user` int(11) NOT NULL,

`time` text NOT NULL,

`message` text NOT NULL,

PRIMARY KEY (`id`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;[/mysql]

Link to comment
Share on other sites

Try this:

<?php
include_once(DIRNAME(__FILE__) .'/globals.php'):
   $count = 0;
$num = $db->fetch_row($db->query("SELECT COUNT(`id`) as `numb` FROM `shout_box`;"));
$amount = $num['numb']-15;
if($amount < 15) {
exit();
}
$chats = $db->query("SELECT `id` FROM `shout_box` ORDER BY `id` ASC LIMIT ". $amount .";");
   while($chat = $db->fetch_row($chats)) {
       $db->query("DELETE FROM `shout_box` WHERE (`id` = ". $chat['id'] ."):");
           $count++;
   }
echo $count.' rows deleted.';
?>
Link to comment
Share on other sites

Oh, now i see what this script is actualy trying to do. What you will have to do is post up the section that display's the 15 message's of the shoutbox, and then ill be able to do it for you. And this im assuming that you want to delete the shout's that are not being displayed right?

Link to comment
Share on other sites

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.   Paste as plain text instead

  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...