passing a number from a str_replace into page numbering script

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
playstatAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

webwomanCommented:
I'm confused. Why do you want to number pages?
0
playstatAuthor Commented:
Because this is not a DB driven site and by pasing a number makes for page numbering. ideal for navigation
0
webwomanCommented:
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
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

playstatAuthor Commented:
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
playstatAuthor Commented:
yes plz sorry about that

0
Wayne CarlsonCommented:
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
playstatAuthor Commented:
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
Wayne CarlsonCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.