Current location: Hot Scripts Forums » Programming Languages » PHP » dividing pages in PHP


dividing pages in PHP

Reply
  #1 (permalink)  
Old 02-03-04, 05:27 PM
Gordon Freeman's Avatar
Gordon Freeman Gordon Freeman is offline
Newbie Coder
 
Join Date: Aug 2003
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
dividing pages in PHP

hey

im making forums for my website but i cant figure out how to divide pages, if like 40 replys are made to a thread

i need a script which would devide pages similar to any other BB around the net... if someone could point out a tutorial i would really appreciate it


Freeman
Reply With Quote
  #2 (permalink)  
Old 02-04-04, 06:50 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
this needs the LIMIT in your mysql_query..
like this :
PHP Code:

mysq_query("SELECT * FROM table_1 LIMIT 0, 10"); 

LIMIT a, b :
a is the record number that mysql should start fetching from ..
b is the number of records to be fetched ,,
meaning in my example : mysqk will fetch 10 records (b) starting from record zero (a)

and you can start bring the other ones by passing the number (a) in your links ..

that's an old script I made that do like this , take a good look at it :
PHP Code:

/*this where we give the link new value .. thanks to spaceman-Spiff*/

        
if (is_numeric($_GET['start_row'])) {
           
$start_row $_GET['start_row'];
                     } else {
           
$start_row 0;
                     }

/*copy varibale value to use it in the previous link*/
$start_row2$start_row;

/*submit MySQL query and recive info from it*/
        
$result=mysql_query("SELECT * FROM books ORDER BY title LIMIT $start_row ,10");
        
$num_row=mysql_num_rows($result);
        
$result2=mysql_query("SELECT * FROM books ORDER BY title");
        
$all_rows=mysql_num_rows($result2);

/*start showing the data found*/
                
echo "<font face=\"tahoma\" size=\"2\">Number of Books records found : <b>" $all_rows "</b></font><br>";

for (
$i=0$i $num_row$i++)       {
            
$row=mysql_fetch_array($result);
            echo 
"<font size=\"2\" face=\"tahoma\" color=\"#686898\"><br><b>" . ($i+1) . '. <u>Title</u>: </font>';
            echo 
"<font size=\"2\" face=\"tahoma\" color=\"#686898\">" htmlspecialchars(stripslashes($row['title'])) . '</b></font>';
            echo 
"<font size=\"2\" face=\"tahoma\"><br><b>Auther: </b>" stripslashes($row['authF']);
                echo 
' ' stripslashes($row['authL']) . "<br>";
                echo 
'<b>Book Number: </b>' stripslashes($row['bookID']);
                echo 
'<br><b>Price: </b>' stripslashes($row['price']) . ' SR</font> <br>';
}

/*if the user is not in first page .. print "previous page" link*/
              
if ($start_row != 0) {
                         echo 
"<a href=\"show.php?start_row=" . ($start_row2-=10);
                         echo 
"\"><font size=\"2\" face=\"tahoma\">Previous Page</a></font>";
                         echo 
' - ';
              }

/*print the next page link to view other books*/
            
if ($num_row >= 10 ) {
        echo 
"<a href=\"show.php?start_row=" . ($start_row+=10);
        echo 
"\"><font size=\"2\" face=\"tahoma\">Next Page</a></font>";
             } else {
        echo 
"<font face=\"tahoma\" size=\"2\">Next Page</font>";
        
mysql_close();
        } 
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]

Last edited by NeverMind; 02-04-04 at 06:52 AM.
Reply With Quote
  #3 (permalink)  
Old 02-07-04, 07:44 AM
Gordon Freeman's Avatar
Gordon Freeman Gordon Freeman is offline
Newbie Coder
 
Join Date: Aug 2003
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
hey thanks!

i'll try to mess with this tonight
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
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
PHP in HTML Pages? ZeoFateX PHP 19 01-04-06 06:42 PM
PHP Help zahir PHP 2 01-29-04 04:29 AM
100 Web Templates & 10 PHP Scripts for sale! HostersUK.co.uk General Advertisements 0 01-10-04 12:31 AM
How to convert php generated pages to SE friendly HTML or PHP(SE friendly) -CLASS 101 crippled PHP 1 11-16-03 06:37 AM


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