View Full Version : automatically deleting rows

03-28-2007, 02:07 AM
is there a way i can automatically delete rows after the number of them reaches a certain number? like if the number of rows reached 160 it starts deleting the last row (oldest row) in the table? i am running a discussion board at www.flashanims.com and it has been producing lots of posts that i think are irrelevant after they hit the 10th page...so any help on this? I'm using phpmyadmin if your wondering.

03-28-2007, 03:45 AM
you would have to run a cron job.

03-28-2007, 03:46 AM
ummm? cron job? please enlighten me :)

03-28-2007, 05:12 AM
a cron job is a script that runs on your system at a specifically scheduled time. you would write the script and have it clean up your data.

really though your data is not significant in size and doesn't even need to be deleted.

what you should do is use a LIMIT clause on your query to only return so many rows related to a topic.

03-28-2007, 09:31 PM
lemme throw a screw ball in here: here is my code

$page = $_GET['page'];
$limit = 10;
$result = mysql_query("select count(*) from comtbl");
$total = mysql_result($result, 0, 0);

// work out the pager values
$pager = Pager::getPagerData($total, $limit, $page);
$offset = $pager->offset;
$limit = $pager->limit;
$page = $pager->page;

// use pager values to fetch data
$query = "select * from comtbl order by postID DESC limit $offset, $limit";
$result = mysql_query($query);
this code is the pagination code i use, nevermind the class it goes with as it is not important. i already set the limit of posts it displays per page...but how would i limit the amount of pages it gets total?

03-29-2007, 01:32 PM
Well this wouldn't be a MySQL issue at this point. You would want to ask this in the PHP forum. And I don't think thats going to be enough information to answer your question. We'll have to see what those functions are actually doing in your paging class file.

I'd suggest looking at the $page and $offset variables in your class file for clues.

03-29-2007, 01:35 PM
moving to PHP forum.

03-29-2007, 03:29 PM
$max_pages = 5;
$limit = 10;
$max_rows = $max_pages * $limit;
$result = mysql_query("select count(*) from comtbl LIMIT ".$max_rows);
$total = mysql_result($result, 0, 0);

That should limit your count and therefore limit your results returned and limit the amount of pages you end up with.

Anyway good luck.

03-29-2007, 03:32 PM
Or you can add in a search criteria with dates. Show all topics greater then 30 days, 60 days... w/e. Thats how vbulletin (this board) does it.