Page 1 of 1
Selecting old database records
Posted: Sun Apr 01, 2007 8:58 pm
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
Posted: Sun Apr 01, 2007 9:05 pm
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;
Posted: Sun Apr 01, 2007 9:34 pm
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!
Posted: Sun Apr 01, 2007 9:42 pm
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