Selecting old database records

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Selecting old database records

Post by Mr Tech »

On the home page of my website, I have 10 news items. I also have an Archives page that shows all the news items I've ever posted...

How do I set it so that on the Archives page, it does not show the 10 news items from the home page? It only shows news item 11, 12, 13 etc etc...

I'm using PHP and MySQL Database.

Thanks
Ben
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

If you're displaying all rows on a single page, maybe the simplest way to do it is to get the total number of records in the table, and place a limit clause at the end of the select query

Code: Select all

$sql = "SELECT .... LIMIT 10, " . $totalRecords-10;
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Post by Mr Tech »

What if I was displaying them in pages? I can get the page part to work, I just need the SQL...

Here is the PHP i would use for the pages...

Code: Select all

$Spagecut = "10";
	$pageid = $_GET[page];
	$page_num = ceil($query_rows / $Spagecut);
	$pageid = ($pageid) ? $pageid : 1;
	$vstart = $Spagecut * ($pageid-1);
	$page_start = floor(($pageid-1)/ $Sdirectcut ) * $Sdirectcut ; 
	$page_end = $page_start + $Sdirectcut; 

	etc...

$query = mysql_query("select * from table limit $vstart,$Spagecut") or die(mysql_error());
Thanks Aaron!
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

I didn't read over your code, but the code that determines the pagination values should assume that the first page is starts at 10, and not 0. Something like $vstart = $pageNumber * 10 instead of $vstart = ($pageNumber * 10) - 10
Post Reply