|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Hi guys,
I have a quick question that probably has an easy answer. I have hundreds of articles on my site and I want to put a simple php function at the bottom of each page that gives people the option of calling the next or previous article in the series. I tried something like : $previous = "$id-1"; $next = "$id+1"; but that was way off. If my first article has the id number 1 how do I get it to insert 2 for the "next tag"? And what about calling an index page for anything less than 1? I am sure there is a simple way to do this. TIA
__________________
Without me my guitar is useless -- http://www.guitarnoise.com http://www.musiccareers.net |
|
#2
|
|||
|
|||
|
Re: A quick way of pulling the next article
Quote:
I am doing the same thing but in my CMS it takes from the mysql database. let me first tell you how i do it and give you suggestion for yours. In the mysql query, i first see the articles that are published so this means my next article link will not be just 1+prevoius article. If your first article has link number 1 (assuming ur not using any database), you can say this ... if your page comes up like this www.yourdomain.com/article?num=1 .. then in your page for previos you will have nothing since this is a starting article .. for thta you gotta put if statement.. but for the next link you might have <a href="articles.php?num=<?php print "$num+1"; ?>"> Next </a> and for calling index page if anything is less than one. you can apply this if statement after some modification if($num==1) <a href="index.php">Home</a> Hope thats ok |
|
#3
|
|||
|
|||
|
Hi, thanks for the reply.
I tried something like you suggested and it worked all right. I was able to make a neat if statement to call a different page if the article number is less than 1. I'm pretty new at this so I am happy with the results. How would you go about making an if statement to cover an article number not yet in the database? Say I have five articles in the database, what can I do with article number five to stop it trying call article number six which hasn't been put in the database yet? I am sure it just needs another if statement but it's beyond my ability at this stage. Thanks again. |
|
#4
|
|||
|
|||
|
What i do is,
when i call mysql_fetch_array , i have a variable that stores the id of the first value of the primary key . for example in $start. now you know that your prev pointer should not go beyond (before) that $start right? so u can have something like if($prev!=$start) print prev button. similarly you can track the last pointer and store it in $end . but make sure when u retreive rows from database, do it as order by asc (thats how i did ) . let me see what more can be added to it
__________________
Hungry for Code Programming works best with a team over one single person
|
|
#5
|
|||
|
|||
|
if you do a mysql_num_rows the articles table you will find out how many articles you have, so if $currentViewedArticle = $numOfArticles then stop. something like that. i think... i hope... i'm tired
![]()
__________________
![]() ![]() "Only Linux users see the end of crashes." - Pl4t0 |
|
#6
|
|||
|
|||
|
What about pulling names
Hi guys,
Following your advice I've been able to set up a simple set of links to the next and previous pages. I've been trying to add one more feature to this but the logic escapes me. How would I be able to include something from the databse that doesn't match the current id, but the id plus or minus one? What I am trying to do is call the article title for the next and previous articles. But so far all my attempts have failed. It always ends up calling the article title for the current id. What do I need to do to accomplish this? Thanks again. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > A quick way of pulling the next article |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|