Solved

passing a number from a str_replace into page numbering script

Posted on 2004-04-02
11
242 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
11 Comments
 
LVL 19

Expert Comment

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

Author Comment

by:playstat
Comment Utility
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
Comment Utility
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
 

Author Comment

by:playstat
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:playstat
Comment Utility
yes plz sorry about that

0
 
LVL 2

Expert Comment

by:Wayne Carlson
Comment Utility
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
Comment Utility
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 500 total points
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

772 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now