Forum Moderators: coopster
Brief description of my problem,
I have an archive of news articles. I keep the seven most recent articles on the front page of my website. I don't want the articles on the front page appearing in the archive until after they are no longer on the front page (no dupe content). So I want to remove the first 7 articles from the archives. I would like to accomplish this within the mysql query if possible.
To retrieve all rows from a certain offset up to the end of the result set, you can use some large number for the second parameter. This statement retrieves all rows from the 96th row to the last:mysql> SELECT * FROM table LIMIT 95,18446744073709551615;
Here is some more detail,
My archives are divided by months, Jan-Dec, so their is always going to be a rollover between months. Using LIMIT, took out the first 7 results for each month. I could use php to check for month and month rollover and then base the query on that, but it's going to require a lot of overhead.
So, is there a way to do a query on a table but leave out the last 7 rows of the table from the query itself?
If I did a row count query and minused seven from that and then used that number in the query like, WHERE row_num != $row_10 AND row_num != $row_11 and so on, would that be a bad idea?
ORDER BY pubdate
ORDER BY pubdate DESC
whichever. If you want the headlines to appear in the opposite order from the query sort, just concatenate differently.
$headlines .= $this_headline; // same order as query
$headlines = $this_headline . $headlines; // reverse order
Will that work for you?
If I did a row count query and minused seven from that and then used that number in the query like, WHERE row_num!= $row_10 AND row_num!= $row_11 and so on, would that be a bad idea?
Probably a bad idea. Presumably row_num would be an auto_incremented primary key? If so, it could be anything and need not be sequential numbers. Better to use a limit clause. You could get a row count and use
$limit = $row_count - 7;
... LIMIT 7, $limit