General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old October 31st, 2002, 05:49 AM
guitarnoise guitarnoise is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 32 guitarnoise User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Question A quick way of pulling the next article

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

Reply With Quote
  #2  
Old October 31st, 2002, 10:52 AM
AmericanD AmericanD is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 81 AmericanD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Re: A quick way of pulling the next article

Quote:
Originally posted by guitarnoise

$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?



TIA


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

Reply With Quote
  #3  
Old November 1st, 2002, 01:08 AM
guitarnoise guitarnoise is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 32 guitarnoise User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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.

Reply With Quote
  #4  
Old November 1st, 2002, 10:22 AM
AmericanD AmericanD is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 81 AmericanD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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

Reply With Quote
  #5  
Old November 1st, 2002, 11:39 AM
wAr-AnGeL wAr-AnGeL is offline
Forum Security
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Behind You
Posts: 479 wAr-AnGeL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m
Reputation Power: 7
Send a message via ICQ to wAr-AnGeL Send a message via AIM to wAr-AnGeL
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

Reply With Quote
  #6  
Old November 10th, 2002, 07:13 PM
guitarnoise guitarnoise is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 32 guitarnoise User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > A quick way of pulling the next article


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway