Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

passing a number from a str_replace into page numbering script

Posted on 2004-04-02
11
Medium Priority
?
251 Views
Last Modified: 2008-03-06
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-->',$dataindex);
      $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,$indexhead); now each page has its number from 1 to X indexes

The thing is that it displays a number for each page fine but for some reason it wont pass on that value to my 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.php');
$links = ob_get_contents();
ob_end_clean();
$indexhead=str_replace('%PAGE%', $links, $indexhead);



<?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=\"$keywordname-1.php\">First</a> <a href=\"$keywordname-$prev.php\">Prev</a> ";
     if($start > 3){
          echo "[<a href=\"$keywordname-$range.php\">$range</a>] ";
     }
     $range += 1;
     if($start > 2){
          echo "[<a href=\"$keywordname-$range.php\">$range</a>] ";
     }
     echo "[<a href=\"$keywordname-$prev.php\">$prev</a>] ";
}
echo "<strong>[$start]</strong> ";
if($start < $nindexes) {
     echo "[<a href=\"$keywordname-$next.php\">$next</a>] ";
     $range = $next+1;
     if($start < ($nindexes-2)){
          echo "[<a href=\"$keywordname-$range.php\">$range</a>] ";
     }
     $range += 1;
     if($start < ($nindexes-3)){
          echo "[<a href=\"$keywordname-$range.php\">$range</a>] ";
     }
     echo "<a href=\"$keywordname-$next.php\">Next</a> <a href=\"$keywordname-$nindexes.php\">Last</a>";
}

?>

Most of the script is based on %tags%   !!!!  

best regards

dc
0
Comment
Question by:playstat
  • 4
  • 2
  • 2
8 Comments
 
LVL 19

Expert Comment

by:webwoman
ID: 10743951
I'm confused. Why do you want to number pages?
0
 

Author Comment

by:playstat
ID: 10748009
Because this is not a DB driven site and by pasing a number makes for page numbering. ideal for navigation
0
 
LVL 19

Expert Comment

by:webwoman
ID: 10748665
Not ideal for navigation. This isn't a book, it's a web site. People don't view the pages in a set order.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:playstat
ID: 10750277
no you misunderstand the page numbering is created for sending to the page numbering code thats how it works but for some reason it wont do it. It displays it onto the page fine below but the first prev line comes out wrong its as if the $start does not know its a number thus it dont work.

page 20 of 100
First Prev [17] [18] [19] [20] [21] [22] [23] Next Last

thats how it comes out each index has a set number so the page XX of INDEX pages

Just I cant send it anywhere

Can you actually help at php scripting

0
 

Author Comment

by:playstat
ID: 10755234
yes plz sorry about that

0
 
LVL 2

Expert Comment

by:Wayne Carlson
ID: 10794818
From your code:
$start='%NUM%';

echo "page $start of $nindexes<br>\n";
$prev = $start-1;
$range = $start-3;
$next = $start+1;


This isn't making sense to me....  

You're setting $start to a string value (%NUM%).  The code isn't going to know that you did a substitution in another string to replace %NUM% with the value of $i.  That is, there is nothing magic about %NUM% to this php code just because you used it as a replacement target earlier.  You need to set $start to a variable containing the numeric value of the current page number.
0
 

Author Comment

by:playstat
ID: 10802960
this is only a small part of the entire many php script files. All i need is an alternative to send the %num% value

well it sends the str replace to a explode which is then looped based on the amount of indexes set from a line by line file


$i is the number(count) indexhead where its going to inserted and %num% being the text on a html template to insert the code

tmp is looped unti the end creating numbers thing is the %num% works fine for each page just need to pass that on to my numbering script

the tmp varable is counted up and each time %num% is replaceed with the correct number. So that part works all I need is to point that number again at the numbers script $start='   ';   etc

Then the rest of the numbers output wil be fine.

SO what can I use instead of str_replacee as its not nessesary in the template i just need the number value to be passed on as a number to the numbers script above
$tmp=str_replace('%NUM%',$i,$indexhead);
Can you provide a means to use the above as a varable for numbers $tmp= "                "; etc or another way to pass on numbers to $start

thx

thx
0
 
LVL 2

Accepted Solution

by:
Wayne Carlson earned 2000 total points
ID: 10803566
I'm having trouble picturing your code structure.  How is your numbering script being called?  If your user gets to a php dynamic page by clicking on a hyperlink, you can include the page number as a parameter in the link...

<a href=showpage.php?pagenum=20>[20]</a>

This HTML can of course be generated by other code.  In showpage.php, you can then get the value $_REQUEST['pagenum'] for $start.

If you're generating all your pages in advance with php code and the users only get the generated html page, it's a different story, but then I don't understand what you mean by "pass on that value".

I'd be glad to look at your code if you want to zip it up with some sample data.  Alternatively, please be more specific on what your control files look like and what the applicable scripts do and when (ie, called by you for generation, invoked through lnks, etc).

Wayne
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month20 days, 15 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question