[nycphp-talk] archive the news to 'next page'
Chris Snyder
chris at psydeshow.org
Sun May 18 10:09:53 EDT 2003
deedee wrote:
>SO...... i'm going to make an HREF for the word Archives to something like new1.php and then i need to somehow start a new starting reference point to display the news. i know i have counted the total available news accurately because i got 11 when i put in the code //print "<B>News ($count_news_results):</B>"; i guess i need to somehow define a variable that is equal to $count_news_results minus the three news articles i previously displayed. but at somepoint i need a loop to end when i run out of news.
>
>
>
The code I'd use would be something like this for the main page -- I'm
not sure what FOUND_ROWS is, I've always used count on a column to find
totals:
// set up the number to display on the main page:
$pagetotal= 3;
// get the total number of articles
$totalquery= "SELECT count(NewsDate) FROM www_news";
$totalresult= mysql_query($totalquery);
if ($array= mysql_fetch_row($totalresult)) $total= $array[0];
// display the first three
$query = "SELECT DATE_FORMAT(NewsDate,'<CENTER>%W<BR>%D %M %Y %r</CENTER>'),News FROM www_news ORDER BY NewsDate DESC LIMIT $pagetotal";
$result = mysql_query($query);
if (!$result) {
die("<h2>!queryErr - error executing query.</h2><br>$query");
}
// use your while loop to print the news...
while ($array= mysql_fetch_row($result)) {
etc. etc. etc.
}
// then for the link to the archives
if ($total > $pagetotal) {
$archive= $total - $pagetotal;
print "<a href='newsarchive.php?offset=$pagetotal'>news archive ($archive stories)</a>";
}
And in newsarchive.php you would use the offset you sent to build the query:
$offset= $_GET['offset'];
$query = "SELECT DATE_FORMAT(NewsDate,'<CENTER>%W<BR>%D %M %Y %r</CENTER>'),News FROM www_news ORDER BY NewsDate DESC LIMIT $offset, -1";
// the -1 means select from $offset to the end of the record set
More information about the talk
mailing list