/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Next Page and Previous Page Links

Hello ?

i am not too sure what type of coding web language i need to try and do this but in my website i have hundreds of different pages that i would like to link together with a simple Next Page and Previous Page link on each web page ?

i have searched everywhere for a method to try and do this but i have had no luck finding anything ?

i would like to find a way to add a functional Next Page and Previous Page link at the bottom of each webpage, but is there a way for the code to link to the next page automatically rather than me typing each one in manually?

PS: all of the webpages that need to be linked are numbered in order, ex) page1.php, page2.php, page3.php etc ?

to post a comment
HTML

20 Comments(s)

Copy linkTweet thisAlerts:
@FangMar 27.2009 — Use php<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>Basic HTML</title>
<?php
function curPageName() {
return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}
preg_match('/page(d+).php$/', curPageName(), $match);

echo '<link rel="prev" href="page' . ($match[1] - 1) . '.php">' . "n";
echo '<link rel="next" href="page' . ($match[1] + 1) . '.php">' . "n";
?>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<script type="text/javascript">

</script>

<style type="text/css">
div a {margin:0 3px;}
</style>

</head>
<body>
<div>
<?php
echo '<a href="page' . ($match[1] - 1) . '.php">previous</a>';
echo '<a href="page' . ($match[1] + 1) . '.php">next</a>';
?>
</div>
</body>
</html>
Don't forget limit checking!
Copy linkTweet thisAlerts:
@mfsgotenauthorMar 27.2009 — Hello ?

thank you so much for replying! ?

i had inserted the<?php

function curPageName() {

return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);

}

preg_match('/page(d+).php$/', curPageName(), $match);

echo '<link rel="prev" href="page' . ($match[1] - 1) . '.php">' . "n";

echo '<link rel="next" href="page' . ($match[1] + 1) . '.php">' . "n";

?>
[/QUOTE]

in the head of my page, and i inserted the
<div>

<?php

echo '<a href="page' . ($match[1] - 1) . '.php">previous</a>';

echo '<a href="page' . ($match[1] + 1) . '.php">next</a>';

?>

</div>
[/QUOTE]


in the body of my code, but due to the lack of my php knowledge, i am still not sure what i have to change in this code for the function to work.

i dont know what to change in the code for it to work with my site pages.
Copy linkTweet thisAlerts:
@FangMar 27.2009 — Only checking the limits of page numbers; lowest and highest.
Copy linkTweet thisAlerts:
@mfsgotenauthorMar 27.2009 — hello ?

sorry for my lack of coding language ? im rly new to php.

where exactly do i type in the lowest and highest page numbers again? ?

thanks again for replying! ?
Copy linkTweet thisAlerts:
@FangMar 28.2009 — &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;title&gt;Basic HTML&lt;/title&gt;
&lt;?php
$lowest=10;
$highest=100;
function curPageName() {
return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}
preg_match('/page(d+).php$/', curPageName(), $match);

if($match[1]&gt;$lowest) {echo '&lt;link rel="prev" href="page' . ($match[1] - 1) . '.php"&gt;' . "n";}
if($match[1]&lt;$highest) {echo '&lt;link rel="next" href="page' . ($match[1] + 1) . '.php"&gt;' . "n";}
?&gt;

&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;

&lt;script type="text/javascript"&gt;

&lt;/script&gt;

&lt;style type="text/css"&gt;
div a {margin:0 3px;}
&lt;/style&gt;

&lt;/head&gt;
&lt;body&gt;
&lt;div&gt;
&lt;?php
if($match[1]&gt;$lowest) {echo '&lt;a href="page' . ($match[1] - 1) . '.php"&gt;previous&lt;/a&gt;';}
if($match[1]&lt;$highest) {echo '&lt;a href="page' . ($match[1] + 1) . '.php"&gt;next&lt;/a&gt;';}
?&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@mfsgotenauthorMar 28.2009 — hello ?

thank you soo much for helping me with this code ?

it works perfectly! ?

i really appreciate your help fang ? thanks! ?
Copy linkTweet thisAlerts:
@mfolandApr 01.2009 — Hi, I have a question.

I am trying to mod this for my dj's where I am working on a dj type thing. It limits their articals they insert to 6 pages. That means 6 articals per page. They are just like journal entries. However.. I have it trying to echo the dj name and so forth.. For the first page I want it to show this:

[code=php]($match[1]<$highest) {echo '<a href="jockpage.php5?dj=$dj;&page=' . ($match[1] + 1) . '"style="font-weight:bold; text-decoration:underline;">previous 6 entries >></a>';}[/code] (posting snippets to show for what I want for page 1. I have the if statement noting if page 1 blah.. )

Page 2 or more..

[code=php]if($match[1]>$lowest) {echo '<a href="jockpage.php5?dj=$dj;&page=' . ($match[1] - 1) . '"style="font-weight:bold; text-decoration:underline;"><< newer 6 entries</a>';}
<b>&nbsp;|&nbsp;</b>
if($match[1]<$highest) {echo '<a href="jockpage.php5?dj=$dj;&page=' . ($match[1] + 1) . '"style="font-weight:bold; text-decoration:underline;">previous 6 entries >></a>';}
[/code]

I have a div style using this. How do I echo the dj's name where it says $dj? I can't get that to work.. Also the page numbers don't auto advance for some reason. There is no number of max pages at this time.. although I have put the max to 1000.

Thanks.
Copy linkTweet thisAlerts:
@FangApr 01.2009 — You want to pass the dj and page number in the query?
Copy linkTweet thisAlerts:
@mfolandApr 02.2009 — Pretty much.. That way I can have it go jockpage.php5?dj=$dj&page=1 etc

At first not have the page so it will show oldest 6 entries.. then once I get to page 2.. it shows a link to show old and new.. All the page number does is work with the limit of 6.. it shows 6 entries per page.
Copy linkTweet thisAlerts:
@FangApr 03.2009 — if($match&gt;$lowest) {echo '&lt;a href="jockpage.php5?dj=' . $dj . '&amp;amp;page=' . ($match[1] - 1) . '"style="font-weight:bold; text-decoration:underline;"&gt;&lt;&lt; newer 6 entries&lt;/a&gt;';}

if($match&lt;$highest) {echo '&lt;a href="jockpage.php5?dj=' . $dj . '&amp;amp;page=' . ($match[1] + 1) . '"style="font-weight:bold; text-decoration:underline;"&gt;previous 6 entries &gt;&gt;&lt;/a&gt;';}
Copy linkTweet thisAlerts:
@mfolandApr 03.2009 — Thank you! Do I also make it say this in the head as well? Also page number says -1 on it when I click the newer views link. The dj does show. Thank you ?
Copy linkTweet thisAlerts:
@mfolandApr 03.2009 — Also, I have a limit on the page, so when I manually type the page number it doesn't show the rest on that page.. and with your script, it still says on the newer entries page=-1.. the previous says the same thing.. it doesn't want to get the current page for some reason. Also I am not sure why it won't work correctly with the limit. ?
Copy linkTweet thisAlerts:
@FangApr 04.2009 — The first snippet was based on a changing page number, you are now using the query to pass information. These are 2 very different methods of changing and limiting page display.?
Copy linkTweet thisAlerts:
@mfolandApr 05.2009 — Here is the SQL. I wonder why it won't change the page number or show the entries on the different pages.

[code=php]<?
$sql = "SELECT * FROM mfoland_djpage.JockSite WHERE dj = '$dj' ORDER BY time ASC LIMIT 1";
$sql_result = mysql_query($sql,$connection);while ($row = mysql_fetch_array($sql_result))
{$page = $row["page"];$title = $row["title"];$body = $row["body"];$time = $row["time"];?>[/code]
Copy linkTweet thisAlerts:
@mfolandApr 05.2009 — Well should be limit 6. I was playing with that to see if I could make the page number work.. I'll try working to GET page, since I am not storing the page number in the db. I just want it to post the entry, then if more than 6 put to next page.
Copy linkTweet thisAlerts:
@GararionApr 07.2009 — Hello Fang, not sure if your still reading this thread but I have a question about your first code you posted in this thread.

I am using dreamweaver to work on a book style of a webpage. What I was hoping to obtain was a code that could be used to advance pages within chapters. The way the site is set up is that each section fo the book is in its own chatper (folder). And then within each of those chapters are various pages, ranging from page1.php to page10.php or higher. When I tried enterign in yoru code to my pages, I'd get this block of code at top of page:
[CODE]<?php
if($match[1]<$highest) {echo '<a href="book' . ($match[1] + 1) . '.php">Next</a>';}
?>[/CODE]
and this at the bottem of the page where I wish the next and Previous links to be: [CODE]<?php
if($match[1]>$lowest) {echo '<a href="page' . ($match[1] - 1) . '.php">previous</a>';}
if($match[1]<$highest) {echo '<a href="page' . ($match[1] + 1) . '.php">next</a>';}
?>[/CODE]


Any help in figuring out why this happening?
Copy linkTweet thisAlerts:
@FangApr 08.2009 — An odd book. Normally pages are numbered consecutively irrespective of chapters. [U]Every[/U] chapter has 10 pages?

Is the top link the chapter number and bottom links pages in the chapter?
Copy linkTweet thisAlerts:
@GararionApr 08.2009 — The reason why I set it up in chatpers is because things will be constantly added to it. So figured it would be easier to have chapters rather then one long page 1,2,3,4,5,6,7,etc.

This way if I wish to add somethign to the first section (chapter) which has 30 pages for example. I would not need to edit the page numbers of all the other sections, just adding a new page called page31.php to that chapter (folder).

Would this be the proper way of doing it or would you sugest another way of doing this?
Copy linkTweet thisAlerts:
@FangApr 08.2009 — Have separate folders:book/chapterXX/pageXX.php
You could hard code the $highest for chapters and for each page/chapter, or have a php routine dynamically read the folder(s) which would allow you to drop a new page in the relevant folder and php would do the rest.
Copy linkTweet thisAlerts:
@GararionApr 08.2009 — Yeah, thats the way I got it set up now.

Now I am tryign to figure out the formating of the page, as described in this thread.
×

Success!

Help @mfsgoten spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...