Current location: Hot Scripts Forums » Programming Languages » PHP » How To Insert Previous Next Record Links


How To Insert Previous Next Record Links

Reply
  #1 (permalink)  
Old 01-02-04, 02:44 AM
cebuy cebuy is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
How To Insert Previous Next Record Links

I have a list of 4700 pages on my website, all dynamically generated via php/mysql and now I want to create a link to the previous record and to the next record in the table for the bottom of each page. What do I do? I do not want to paginate necessarily. I want the title of the page in the link (not next or previous).

For example lets say that "mortgage loan" is the keyword phrase (or title) listed in my database for the page mortgage-loan.html. The current page is "mortgage loans" and mortgage-loans.html. The next page is keyword "mortgage refinancing" for the page mortgage-refinancing.html. I want links that look like...

mortgage loan < current page >mortgage refinancing

My database has the titles of each page in one column and a unique auto incremented column called ID. (but I am not sure if all numbers are a perfect 1,2,3,4,5,6,7... any more)

Something like...

ID Title
--+------------------------------+
1 mortgage loan
2 mortgage loans
3 mortgage refinancing

etc, etc, & so on... (4700 more)

How do I create a navigation link bar like this? I am sure it is simple. Could someone help a php newbie on this? :-)

--Chris
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 01-02-04, 03:08 AM
Infinite_Hackers's Avatar
Infinite_Hackers Infinite_Hackers is offline
Coding Addict
 
Join Date: Dec 2003
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Maby not exactally what you want, but this limites the number of results displayed.

if there are more then 5 results, it will make a new page i.e:

Previous 1 2 3 4 5 6 7 8 9 10 11 12 13 Next

PHP Code:

       $limit 5;


       
$query1 "SELECT * FROM YOUR_TABLE";

    
$numresults mysql_query($query1);
    
$numrows mysql_num_rows($numresults);

        
$dis '';

    if (empty(
$offset)) {
        
$offset 0;
    } 
    
// The continuing next-prev code
    
$pages intval($numrows $limit);

    if ((
$pages != and $pages != 1) or ($pages == and ($numrows $limit))) {
        if (
$offset != 0) {
            
$prevoffset $offset $limit;
            
$dis .= "<a href=\"$PHP_SELF?offset=$prevoffset\">Previous</a> ";
        } 

        if (
$numrows $limit) {
            
$pages++;
        } 

        for (
$i 1;$i <= $pages;$i++) {
            
$newoffset $limit * ($i-1);
            If (
$offset != $newoffset) {
                
$dis .= "<a href=\"$PHP_SELF?offset=$newoffset\">$i</a> ";
            } else {
                
$page_num $i;

                
$total_num_page $last_page_num ceil($total_num_user $records_per_page);

                
$displays "<center><b>Displaying the page $page_num out of $last_page_num.</b></center>\n";

                
$dis .= "<b>$i</b> ";
            } 
        } 

        if (
$pages != or (($pages == and ($numrows $limit)))) {
            if ((
$offset $limit) < $numrows) {
                
$newoffset $offset $limit;
                
$dis .= "<a href=\"$PHP_SELF?offset=$newoffset\">Next</a>";
            } 
        } 
    }


$result mysql_query("SELECT * FROM YOUR_TABLE LIMIT $offset$limit");
while (
$rec mysql_fetch_array($result)) 
{
 ...
}
echo 
$displays '<br>';
echo 
$dis

Last edited by Infinite_Hackers; 01-02-04 at 03:17 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 01-02-04, 09:52 AM
cebuy cebuy is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
That is some cool code but is not exactly what I wanted. Although I always wondered how to do the Google page number navigation like they did! Thanks! However, what I wanted was to draw on the previous record and the next record and make links out of the titles listed in my database. Any idea on how to get that? Is it in the way we query the mysql? Like add a -1 or +1 to the WHERE ID=$ID+1 (or -1 ) ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
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
detail data, with next previous record ivan PHP 2 12-30-03 07:40 PM
previous & next links assistance needed... Soulidified PHP 2 12-29-03 04:42 PM
Upload file to table so ONLY files tied to primary key are displayed in record? grafixDummy PHP 4 12-20-03 05:28 PM
MySQL table problem perleo PHP 9 12-16-03 02:16 PM
how do i add a record AND send an email in one step? nickleidecker ASP 2 10-14-03 08:12 PM


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