Hello...
Here is what I want to do, but for the life of me I can't remember what I need to do to get it there....
I have a page that displays the last 20 things in the table. I want the next page start at item 21. So what I want is to get the query to take the last rows # and - 20 from it and start there. Am I making sense?
THe 1st page I have with a limit of 20 - all the pages after this I want a limit of 10. The 1st page isn't a problem. Just starting off with # 21 is giving me the issue.
$query = ("SELECT DATE_FORMAT(news_date, '%M %d, %Y')
AS news_date1, news_id, news_title, news_snippet
FROM bm_news
ORDER BY news_date DESC") or die ("Error ".mysql_error());
$limit = 20;
$result = mysql_query($query);
$totalrows = mysql_num_rows($result) or die ("Error ".mysql_error());
//Print title and page number
if ($page > 1){
echo '<center><h3>' . "News Archive - Page " . $page . '</h3></center>';
}
else{
echo '<center><h3>' . "News Archive - Page 1" . '</h3></center>';
}
if(empty($page)){
$page = 1;
}
else {
$page = $_GET['page'];
}
$limitvalue = $page * $limit - ($limit);
$result = mysql_query("$query LIMIT $limitvalue, $limit") or die("Error ".mysql_error());
if(mysql_num_rows($result) == 0){ //if no row in table
echo("Nothing to Display!");
}
else { //there are rows in table
echo "<center>";
while($row = mysql_fetch_array($result))
{
$news_id = $row['news_id'];
$news_date = $row['news_date1'];
$news_title = $row['news_title'];
$news_snippet = $row['news_snippet'];
echo '<table border="0" width=90% cellspacing="0" height="1" cellpadding="0">';
echo '<br><tr><td width=20% height="1">
<img border="0" src="http://www.brew-monkey.com/images/dot-red.gif" width="7" height="7"> <b>' . $news_title . '</b></td></tr></table>
<table border="0" width=90% cellspacing="0" height="1" cellpadding="0">
<tr><td width=90% height="1">';
echo '<tr><td width=90%>' . $news_date . ' - ' . $news_snippet . ' (<a href="/news.php?id=' . $news_id . '">more...</a>)</td></tr></table>';
}
echo '<br><br>';
//PROVIDE THE PREVIOUS LINK
if($page > 1){
$pageprev = $page - 1;
echo("<a href=\"newsarchive.php?page=$pageprev\">PREVIOUS ".$limit."</a> - ");
}
else{
echo("PREVIOUS ".$limit." - ");
}
//---------------------------
$numofpages = $totalrows / $limit;
//PROVIDE THE NUMBERING OF PAGES
for($i = 1; $i <= $numofpages; $i++){
if($i == $page){
echo($i." ");
}
else{
if($i <= 30){
echo("<a href=\"newsarchive.php?page=$i\">$i</a> ");
}
if($i == 30){
echo "<br />";
}
if($i > 30){
echo("<a href=\"newsarchive.php?page=$i\">$i</a> ");
}
}
}
//---------------------------
//CHECK WHETHER THERE ARE STILL ANY REMAINDERS
if(($totalrows % $limit) != 0){
if($i == $page){
echo($i." ");
}
else{
echo("<a href=\"newsarchive.php?page=$i\">$i</a> ");
}
}
//---------------------------
//CHECK IF PAGES IN FRONT THE CURRENT PAGE
if(($totalrows - ($limit * $page)) > 0){
$pagenext = $page + 1;
echo(' - '."<a href=\"newsarchive.php?page=$pagenext\">NEXT ".$limit ."</a>");
}
else{
echo(" - NEXT ". $limit);
}
echo "</center>";
}
?>
Thanks for the help.
Chris