Current location: Hot Scripts Forums » Programming Languages » PHP » browse by page


browse by page

Reply
  #1 (permalink)  
Old 10-09-05, 04:35 PM
lylesback2 lylesback2 is offline
Wannabe Coder
 
Join Date: Dec 2003
Posts: 119
Thanks: 0
Thanked 0 Times in 0 Posts
browse by page

im working on a news posting script, that only displays the latest 5 posts.

does anyone have an example of a script, that allows you to read articles 5-10, 10-15, 15-20, etc..

Im looking at how to coding page.php, and displaying results from the database. the news articles are seperated by column 'id' 1,2,3,4, etc..

this is an example off the footer of a site i visit:
Attached Images
File Type: jpg pages.JPG (2.4 KB, 59 views)
Reply With Quote
  #2 (permalink)  
Old 10-10-05, 05:12 AM
Richard's Avatar
Richard Richard is offline
Wannabe Coder
 
Join Date: Sep 2005
Location: Oxford, UK
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
What I think you'd need to do is set an offset variable, this indicates how far you are in the database (i.e, what page you're on). Something like...
PHP Code:

$sql mysql_query("SELECT * FROM dbNews ORDER BY newsDate DESC");

$i 0$newsPrinted 0;
while(
$News mysql_fetch_array($sql)) {
    if ((
$_GET['offset'] == $i) && ($newsPrinted 5) {
        
// Echo the news and add a printed
        
$newsPrinted++;
    } elseif (
$newsPrinted == 5) {
        break;
    }
    
$i++;

I think you might be able to do something similar with a MySQL statement...i'm not sure though.
Reply With Quote
  #3 (permalink)  
Old 10-10-05, 01:57 PM
dennispopel dennispopel is offline
Coding Addict
 
Join Date: Mar 2005
Posts: 263
Thanks: 0
Thanked 0 Times in 0 Posts
Hello,

There is a very nice MySQL feature called LIMIT:

$start = (int)($_GET['start'] / 5)
mysql_query("SELECT * FROM dbNews ORDER BY newsDate DESC LIMIT $start, 5");

Then you can come up with the code that displays links like

$url = "<a href='mypage.php?start=$start'>Page $start</a> "

See if you can create the loop
__________________
onPHP5.com - PHP5: Articles, News, Tutorials, Interviews, Software and more
Reply With Quote
  #4 (permalink)  
Old 10-10-05, 02:28 PM
Richard's Avatar
Richard Richard is offline
Wannabe Coder
 
Join Date: Sep 2005
Location: Oxford, UK
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
ooh, i didn't realise you could set a start variable for the LIMIT function...cool
Reply With Quote
  #5 (permalink)  
Old 10-11-05, 01:49 PM
dennispopel dennispopel is offline
Coding Addict
 
Join Date: Mar 2005
Posts: 263
Thanks: 0
Thanked 0 Times in 0 Posts
Hello,

Yes, MySQL allows this. Anyways you should not iterate thru each row to get to the start row, you should have used the mysql_data_seek function (similar functions help imitate the LIMIT clause for non-supporting DBMS).
__________________
onPHP5.com - PHP5: Articles, News, Tutorials, Interviews, Software and more
Reply With Quote
  #6 (permalink)  
Old 10-14-05, 11:59 AM
lylesback2 lylesback2 is offline
Wannabe Coder
 
Join Date: Dec 2003
Posts: 119
Thanks: 0
Thanked 0 Times in 0 Posts
ahh that was so easy! thanks
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Classified Ads skipper23 Perl 3 11-22-05 02:22 AM
Passing a variable to another page tapir PHP 8 02-16-05 05:38 PM
need help creating an update & confirm page mikewooten PHP 1 11-08-04 04:28 PM
page browsing problem mivec PHP 3 04-17-04 03:43 AM
Classified Ads skipper23 Perl 2 12-30-03 03:43 AM


All times are GMT -5. The time now is 06:14 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.