Solved

Another hopefull easy php question

Posted on 2008-06-23
12
188 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

785 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