Solved

Another hopefull easy php question

Posted on 2008-06-23
12
189 Views
Last Modified: 2008-11-21
I got , with help, the "next.gif" images  in this script to show up but the "here.gif" and "prev.gif" don't display.

Here's what I see when I click source

<a href="_1.php"><img src="http://www.mybelovedangels.com/images/next.gif" alt="1" border="0"></a><a href="_2.php"><img src="http://www.mybelovedangels.com/images/next.gif" alt="2" border="0"></a><a href="_3.php"><img src="http://www.mybelovedangels.com/images/next.gif" alt="3" border="0"></a><a href="_4.php"><img src="http://www.mybelovedangels.com/images/next.gif" alt="4" border="0"></a><a href="_5.php"><img src="http://www.mybelovedangels.com/images/next.gif" alt="5" border="0"></a>
:
Heres the code I'm trying to get to work (it does change pages):
 
<?php
//This script is created by Reptilian Feline
//www.reptilian-feline.net
//If you use it, please link to my site
$full_path = getenv("REQUEST_URI");
//put the base URL in case you need it
$base = "http://www.mybelovedangels.com/catalog/main-log/";
//Get the name of the file
$page_file = basename($full_path);
//The files are named file_1.php, file_2.php, etc. Extract number from it.
$page_num = substr($page_file
, strrpos($page_file, "_") + 1
, strpos($page_file, ".php") - strrpos($page_file, "_") - 1
);
$partial_path = substr($page_file, 0, strrpos($page_file, "_"));
//Build array of pagenumbers. Here are ten pages.
$all_pages = array (1,2,3,4,5);
 
foreach ($all_pages as $all_page)
{
//Create link to all the previus pages and put in prev-image.
if ($all_page < $page_num) 
{
print "<a href=\"$partial_path"."_". $all_page . ".php\"><img src=\"http://www.mybelovedangels.com/images/prev.gif\" alt=\"$all_page\" border=\"0\"></a>";
}
//Create I-am-here-image.
elseif ($all_page == $page_num) 
{
print "<img src=\"http://www.mybelovedangels.com/images/here.gif\" alt=\"$page_num\" border=\"0\">";
}
//Create links to all the next pages and put in next-image.
else 
{
print "<a href=\"$partial_path"."_" . $all_page . ".php\"><img src=\"http://www.mybelovedangels.com/images/next.gif\" alt=\"$all_page\" border=\"0\"></a>";
}
}
?>

Open in new window

0
Comment
Question by:Freejoy
  • 7
  • 2
12 Comments
 

Author Comment

by:Freejoy
ID: 21852471
By the way just in case it matters I changed the following in the above code:

[code]
$base = "http://subomain.domain.ext";
[/code]

to:

[code]

$base = "http://www.mybelovedangels.com/catalog/main-log/";
[/code]

Thanks

0
 
LVL 1

Expert Comment

by:binarydesignnz
ID: 21852510
The image links are still pointing to "http://www.mybelovedangels.com/catalog/main-log/images/next.gif" where they should be "http://www.mybelovedangels.com/images/next.gif"

May I ask, why are you using graphics for this when you could just use &lt, X and &gt ?  This may simplify things?
0
 

Author Comment

by:Freejoy
ID: 21852592
I'm just trying to get it going correctly so I was trying to follow the directions.

my images are at: mybelovedangels.com/images.gif

these pages are in: mybelovedangels.com/catalog/main-log/_2.php

I mention this because i changed:
$base = "http://www.mybelovedangels.com/catalog/main-log/";

to:
$base = "http://www.mybelovedangels.com/";
it had no effect

I kinda like using the images a little because after it's going I could change the images to something neat....maybe.  They hardly weigh anything.


0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:Freejoy
ID: 21852605
Oh yea, the thing is the "next.gif" images are working.  It the other two that aren't
0
 
LVL 4

Expert Comment

by:trippy1976
ID: 21852624
Well, I think you are not parsing $page_num correctly.  What is the output from that?  Have you printed it to see what it is?

The only part of your if statement ever triggering is "else" so $all_page is

- either always larger than and not equal to what you are getting in $page_num
- $page_num is not right... probably not a number.  Either you're getting some other character in it or you may need to do some kind of "intval" cast from string to a number.

I think your substr call is fubared.  those can be tricky
0
 

Author Comment

by:Freejoy
ID: 21852678
I kinda see what your saying.  

So what's the solution to get it working correctly?(smile)

Like the bad guy on "Die Hard" said,  "Give me the code!"

 
0
 
LVL 4

Accepted Solution

by:
trippy1976 earned 500 total points
ID: 21852762
I'd have to be running your script inside your environment.

Put this code after the line you set $page_num on:

die($page_file . " :: " .  $page_num)

Then cut/paste that output here so I can see it.  Then you will be sure to know what is in both variables, which will be very helpful to you.

I think you are going to want to do something like

$substStart = strrpos($page_file, "_");
$substEnd = len($page_file) - $strrpos($page_file, ".php");
$page_num = substr($pagefile, $substStart, $substEnd);

You might need to add 1 to the start variable.  But that will be pretty close.
$substStart = strrpos($page_file, "_");
$substEnd = len($page_file) - $strrpos($page_file, ".php");
$page_num = substr($pagefile, $substStart, $substEnd);

Open in new window

0
 

Author Comment

by:Freejoy
ID: 21852794
OK I'm on it!

But what do/did you mean by,  "Have you printed it to see what it is?"
0
 

Author Comment

by:Freejoy
ID: 21852833
I added the code exactly like below and when I went to open the page I get this:

PHP Parse error: syntax error, unexpected T_VARIABLE in D:\hshome\freejoy\mybelovedangels.com\catalog\main-log\_4.php on line 899


Here's  how I  changed the code so far, I just added the one line:
<?php
//This script is created by Reptilian Feline
//www.reptilian-feline.net
//If you use it, please link to my site
$full_path = getenv("REQUEST_URI");
//put the base URL in case you need it
$base = "http://www.mybelovedangels.com/";
//Get the name of the file
$page_file = basename($full_path);
//The files are named file_1.php, file_2.php, etc. Extract number from it.
$page_num = substr($page_file
, strrpos($page_file, "_") + 1
, strpos($page_file, ".php") - strrpos($page_file, "_") - 1
);
die($page_file . " :: " .  $page_num) 
 
$partial_path = substr($page_file, 0, strrpos($page_file, "_"));
//Build array of pagenumbers. Here are ten pages.
$all_pages = array (1,2,3,4,5);
 
foreach ($all_pages as $all_page)
{
//Create link to all the previus pages and put in prev-image.
if ($all_page < $page_num) 
{
print "<a href=\"$partial_path"."_". $all_page . ".php\"><img src=\"http://www.mybelovedangels.com/images/prev.gif\" alt=\"$all_page\" border=\"0\"></a>";
}
//Create I-am-here-image.
elseif ($all_page == $page_num) 
{
print "<img src=\"http://www.mybelovedangels.com/images/here.gif\" alt=\"$page_num\" border=\"0\">";
}
//Create links to all the next pages and put in next-image.
else 
{
print "<a href=\"$partial_path"."_" . $all_page . ".php\"><img src=\"http://www.mybelovedangels.com/images/next.gif\" alt=\"$all_page\" border=\"0\"></a>";
}
}
?>

Open in new window

0
 

Author Comment

by:Freejoy
ID: 21853112
Here's how I finally added your  code

On line 905 I get a PHP Parse error: syntax error, unexpected T_VARIABLE .  That's this line:

 $partial_path = substr($page_file, 0, strrpos($page_file, "_"));

Here's the complete code how I've got it together so far.
<?php
//This script is created by Reptilian Feline
//www.reptilian-feline.net
//If you use it, please link to my site
$full_path = getenv("REQUEST_URI");
//put the base URL in case you need it
$base = "http://www.mybelovedangels.com/catalog/main-log/";
//Get the name of the file
$page_file = basename($full_path);
//The files are named file_1.php, file_2.php, etc. Extract number from it.
 
$substStart = strrpos($page_file, "_");
$substEnd = len($page_file) - $strrpos($page_file, ".php");
$page_num = substr($pagefile, $substStart, $substEnd);
 
 
 
die($page_file . " :: " .  $page_num) 
 
 
 
 
$partial_path = substr($page_file, 0, strrpos($page_file, "_"));
//Build array of pagenumbers. Here are ten pages.
$all_pages = array (1,2,3,4,5);
 
foreach ($all_pages as $all_page)
{
//Create link to all the previus pages and put in prev-image.
if ($all_page < $page_num) 
{
print "<a href=\"$partial_path"."_". $all_page . ".php\"><img src=\"http://www.mybelovedangels.com/images/prev.gif\" alt=\"$all_page\" border=\"0\"></a>";
}
//Create I-am-here-image.
elseif ($all_page == $page_num) 
{
print "<img src=\"http://www.mybelovedangels.com/images/here.gif\" alt=\"$page_num\" border=\"0\">";
}
//Create links to all the next pages and put in next-image.
else 
{
print "<a href=\"$partial_path"."_" . $all_page . ".php\"><img src=\"http://www.mybelovedangels.com/images/next.gif\" alt=\"$all_page\" border=\"0\"></a>";
}
}
?>

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

808 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