NYCPHP Meetup

NYPHP.org

[nycphp-talk] archive the news to 'next page'

Christopher R. Merlo cmerlo at turing.matcmp.ncc.edu
Sun May 18 12:45:48 EDT 2003


Deedee:
Here's what I put in my left-side nav thing:

***

$news_query = "select topic, date from site_news order by date desc";
$news_result = @mysql_query( $news_query );

// Notice on next line, I assume that there's more than two news items

for( $i = 0; $i < 2; $i++ ) {
  $row = @mysql_fetch_assoc( $news_result );
    print "          <p><b>" . $row[ "topic" ] . "</b><br />"
        . date( "j M Y g:i a", strtotime( $row[ "date" ] ) )
  . "</p>\
";
}
print "          <p align=\\"left\\">";
print_link( "$docroot/news.php", "Read Site News..." );
print "</p>\
";

***

The assumption works because it's my site top to bottom.  YMMV.

The page news.php, which shows all the news, looks like this:

***

// Select all entries from site_news table
$news_query = "select * from site_news order by date desc";
$news_result = @mysql_query( $news_query );

// And display them
while( $row = @mysql_fetch_assoc( $news_result ) ) {
  print "<p class=\\"main\\"><font color=\\"blue\\"><large><b>"
      . $row[ "topic" ] . "</b></large></font> <small>[ "
      . date( "j M Y g:i a", strtotime( $row[ "date" ] ) )
      . " ]</small></p>\
";
  print "<p class=\\"main\\">" . $row[ "news" ] . "</p>\
";
}

***

BTW, just so you're not confused, this is code from my devel site.
The live site actually displays the first two items on the front page,
not just headlines and dates, and doesn't display anything in the nav
bar.

HTH!
-c

-- 
cmerlo at turing.matcmp.ncc.edu        http://turing.matcmp.ncc.edu/~cmerlo

"Nuclear war would really set back cable."
  -- Ted Turner



More information about the talk mailing list