playstat
asked on
prev and next href based on landing page
Hi lozloz
Instead of creating a numbers system what i am looking for is a simple previous page and next page based on the landing page.
for example my pages are named index-1.php index-2.php etc etc
there is a limit based on the amount of index pages created that part of the script is done.(number of lines per text file divide by 10 per page = $nindexes
I need somehow to create a prev and next based on the number of that index page ($start) would be the varable.
Say a user lands on page 45 the prev should equal page 44 and the next equal page 46
the first page should only have next and the last page should only have prev
the design outputs per page have to tally with the index page number
How would i got about that
One the script know the amount of indexes so say 100 how would you be able to output per page with the above setup.
the thing is that some parts have 500+ indexes and a numbering system is impractical so just a simple prev and next to link to each page until it reaches the last index page.
Best regards
Dc
Instead of creating a numbers system what i am looking for is a simple previous page and next page based on the landing page.
for example my pages are named index-1.php index-2.php etc etc
there is a limit based on the amount of index pages created that part of the script is done.(number of lines per text file divide by 10 per page = $nindexes
I need somehow to create a prev and next based on the number of that index page ($start) would be the varable.
Say a user lands on page 45 the prev should equal page 44 and the next equal page 46
the first page should only have next and the last page should only have prev
the design outputs per page have to tally with the index page number
How would i got about that
One the script know the amount of indexes so say 100 how would you be able to output per page with the above setup.
the thing is that some parts have 500+ indexes and a numbering system is impractical so just a simple prev and next to link to each page until it reaches the last index page.
Best regards
Dc
ASKER
would it be possible with out all the html info ive tried to use it but no avail one thing is that the pages are generated into actual php pages this is not database driven bu as is created the only was for it to know what page is what i guess is by saving it to a text file when it compiling and then connecting to that when the next and prev is being used at the mo all i use is this code below
<?php // keep it free from as much HTML as possible as the site is template driven and all inplace any additionals will just mess with it
$limit=50; //get this from row count or page count
$limit2=$limit+1;
$limit3=$limit-1;
$now=$_GET['page'];
if($now=="0")
{
$now=1;
}
$start=$now+1;
$end=$start+70+1; //where 20 is $nindexes go
if ($end >= $limit)
{
$end=$limit;
}
$back=$start-2;
$next=$start+1;
if($back<0)
{
$back=0;
}
if($back>=1)
{
echo "<a href=\"index-$limit3.php\" >prev</a> |";
}
echo" $now |";
for($start;$start<=$end;$s tart++)
{
echo "<a href=\"index-$start.php#in dex-$start \" title=\"index-$start\">$st art</a> |";
}
{
echo " <a href=\"index-$limit2.php\" >next</a>" ; //somehow this needs to know the end but the prob lies when the next is used
} // how can you display the next 50 with limit involved so that the next 50 pages
// display 51 to 100 or of the total indexes reached are displayed and so forth until its index limit is reached
//if($start<=$limit)
//{
//echo" .. |";
//$tens=ceil(($end/10)+1)* 10;
//for($i=1;$i<=8;$i++)
//{
//If($tens<$limit)
//{
//echo " <a href=\"$keywordname-$start .php?page= $tens\">$t ens</a> |";
//$tens=$tens+10;
//}
//}
//echo " <a href=\"$keywordname-$start .php?page= $next\">&g t;</a>";
//}
?>
<?php // keep it free from as much HTML as possible as the site is template driven and all inplace any additionals will just mess with it
$limit=50; //get this from row count or page count
$limit2=$limit+1;
$limit3=$limit-1;
$now=$_GET['page'];
if($now=="0")
{
$now=1;
}
$start=$now+1;
$end=$start+70+1; //where 20 is $nindexes go
if ($end >= $limit)
{
$end=$limit;
}
$back=$start-2;
$next=$start+1;
if($back<0)
{
$back=0;
}
if($back>=1)
{
echo "<a href=\"index-$limit3.php\"
}
echo" $now |";
for($start;$start<=$end;$s
{
echo "<a href=\"index-$start.php#in
}
{
echo " <a href=\"index-$limit2.php\"
} // how can you display the next 50 with limit involved so that the next 50 pages
// display 51 to 100 or of the total indexes reached are displayed and so forth until its index limit is reached
//if($start<=$limit)
//{
//echo" .. |";
//$tens=ceil(($end/10)+1)*
//for($i=1;$i<=8;$i++)
//{
//If($tens<$limit)
//{
//echo " <a href=\"$keywordname-$start
//$tens=$tens+10;
//}
//}
//echo " <a href=\"$keywordname-$start
//}
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
that is well close works really well except the start is the prob cant seem to find what part when the pages are made somehow i need to loop this around and then start goes up one number each time in sync with the pages then it would be spot on.
Well, you must know what the number of the page is because you have to name it index-whatever.php so can't you just pass that value into $start in the above code?
ASKER
thx reapz well apprieciated but i have another if yer interested :0) will post tomorrwz for you c yer l8rs
ASKER
Hi there
I am having problems with my script. For numbers it works fine each index page has its own inserted number This is how it works
Reads a html template phpindex
Inserts this into an explode (on the template <-start-> <-end-> this then loops around based on the amount of words of a text file divided by results per page which is 10
$tmp = explode('<!--start-->',$da taindex);
$indexhead = $tmp[0];
$tmp = explode('<!--end-->',$tmp[ 1]);
$indexcenter = $tmp[0];
$indexbase = $tmp[1];
This gives the amount of indexes.
Now the way i have done this is to use the usual count for ($i=1; $i<=$nindexes; $i++) this counts up etc the amount of indexes and assigns using str_replace a number. Within the template is a tag so it replaces it etc
$tmp=str_replace('%NUM%,$i ,$indexhea d); now each page has its number from 1 to X indexes
The thing is that it displays a number for each page fine if the template hs %NUM% in it but for some reason it wont pass on that value to the page numbering below
Is there anyway to pass on this number to the code below after its inserted it from the template tag.
The code bolow works spot on if $start=10; for example replaced with a number. just it wont do it for some reason with '%NUM%' I think its the str_replace thats the prob. Any aternatives.
Ive used this to insert it into the template while using a %TAG%
ob_start();
include('indexnumbering.ph p');
$links = ob_get_contents();
ob_end_clean();
$indexhead=str_replace('%P AGE%', $links, $indexhead);
the $nindexes it already knows from the rest of the script
<?php
$start='%NUM%';
echo "page $start of $nindexes<br>\n";
$prev = $start-1;
$range = $start-3;
$next = $start+1;
if($start > 1) {
echo "<a href=\"$index-1.php\">Firs t</a> <a href=\"$index-$prev.php\"> Prev</a> ";
if($start > 3){
echo "[<a href=\"$index-$range.php\" >$range</a >] ";
}
$range += 1;
if($start > 2){
echo "[<a href=\"$index-$range.php\" >$range</a >] ";
}
echo "[<a href=\"$index-$prev.php\"> $prev</a>] ";
}
echo "<strong>[$start]</strong> ";
if($start < $nindexes) {
echo "[<a href=\"$index-$next.php\"> $next</a>] ";
$range = $next+1;
if($start < ($nindexes-2)){
echo "[<a href=\"$index-$range.php\" >$range</a >] ";
}
$range += 1;
if($start < ($nindexes-3)){
echo "[<a href=\"$index-$range.php\" >$range</a >] ";
}
echo "<a href=\"$index-$next.php\"> Next</a> <a href=\"$index-$nindexes.ph p\">Last</ a>";
}
?>
Most of the script is based on %tags% !!!!
best regards
dc
I am having problems with my script. For numbers it works fine each index page has its own inserted number This is how it works
Reads a html template phpindex
Inserts this into an explode (on the template <-start-> <-end-> this then loops around based on the amount of words of a text file divided by results per page which is 10
$tmp = explode('<!--start-->',$da
$indexhead = $tmp[0];
$tmp = explode('<!--end-->',$tmp[
$indexcenter = $tmp[0];
$indexbase = $tmp[1];
This gives the amount of indexes.
Now the way i have done this is to use the usual count for ($i=1; $i<=$nindexes; $i++) this counts up etc the amount of indexes and assigns using str_replace a number. Within the template is a tag so it replaces it etc
$tmp=str_replace('%NUM%,$i
The thing is that it displays a number for each page fine if the template hs %NUM% in it but for some reason it wont pass on that value to the page numbering below
Is there anyway to pass on this number to the code below after its inserted it from the template tag.
The code bolow works spot on if $start=10; for example replaced with a number. just it wont do it for some reason with '%NUM%' I think its the str_replace thats the prob. Any aternatives.
Ive used this to insert it into the template while using a %TAG%
ob_start();
include('indexnumbering.ph
$links = ob_get_contents();
ob_end_clean();
$indexhead=str_replace('%P
the $nindexes it already knows from the rest of the script
<?php
$start='%NUM%';
echo "page $start of $nindexes<br>\n";
$prev = $start-1;
$range = $start-3;
$next = $start+1;
if($start > 1) {
echo "<a href=\"$index-1.php\">Firs
if($start > 3){
echo "[<a href=\"$index-$range.php\"
}
$range += 1;
if($start > 2){
echo "[<a href=\"$index-$range.php\"
}
echo "[<a href=\"$index-$prev.php\">
}
echo "<strong>[$start]</strong>
if($start < $nindexes) {
echo "[<a href=\"$index-$next.php\">
$range = $next+1;
if($start < ($nindexes-2)){
echo "[<a href=\"$index-$range.php\"
}
$range += 1;
if($start < ($nindexes-3)){
echo "[<a href=\"$index-$range.php\"
}
echo "<a href=\"$index-$next.php\">
}
?>
Most of the script is based on %tags% !!!!
best regards
dc
Why not just put something like this above and/or below your output...
<table width="100%" border="0" cellspacing="3" cellpadding="3">
<tr>
<td><div align="left"><?php if($page > 1) { ?><< <a href="index-<?php echo $page-1; ?>.php">Prev</a> <?php } ?></div></td>
<td><div align="center">Page <?php echo $page; ?> of <?php echo $nindexes; ?></div></td>
<td><div align="right"><?php if($page < $nindexes) { ?><a href="index-<?php echo $page+1; ?>.php">Next</a> >><?php } ?></div></td>
</tr>
</table>