bladewolf2010 Posted July 26, 2010 Posted July 26, 2010 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] Quote
Haunted Dawg Posted July 26, 2010 Posted July 26, 2010 All you need in that file is this: <?php include_once(DIRNAME(__FILE__).'globals.php'); if($ir['userid'] !== 1) { exit; } mysql_query('TRUNCATE TABLE `shout_box`'); echo 'Table cleaned!'; ?> Quote
Haunted Dawg Posted July 26, 2010 Posted July 26, 2010 You'll need to enter the file manually, but you could setup a cron to go to that file, but then modifying would be needed. So it's useless much, just run it manually. Quote
Danny696 Posted July 26, 2010 Posted July 26, 2010 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.'; ?> Quote
Haunted Dawg Posted July 26, 2010 Posted July 26, 2010 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? Quote
Danny696 Posted July 26, 2010 Posted July 26, 2010 The edit i added should work. He only had one chat in the table, and it was making it error. My edit made sure that if there were less than 15, nothing would happen or errror :) Quote
bladewolf2010 Posted July 30, 2010 Author Posted July 30, 2010 Still doesn't delete the chats from the DB Quote
bladewolf2010 Posted July 30, 2010 Author Posted July 30, 2010 how could i add it to my cron_hour.php so it deletes all it? Quote
rulerofzu Posted July 30, 2010 Posted July 30, 2010 You want to delete all messages per hour? TRUNCATE the table. Quote
bladewolf2010 Posted July 30, 2010 Author Posted July 30, 2010 what would I put in my cron_hour.php? Quote
rulerofzu Posted July 30, 2010 Posted July 30, 2010 HD showed you the query. mysql_query("TRUNCATE TABLE shout_box"); Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.