PDA

View Full Version : Weird Problem



Mike
01-04-2004, 01:49 PM
Hi all,

On a script I am using it has "echo $page-1;" as part as a url. It is meant to give one number less than the current page number. However, it actually gives the current number AND the number less. So say if your current page number was 7, and you wanted to go back a page, the url would say /76. Get me?:)

The same happens with "echo $page+1;"...

Please could someone help?

Thanks,
Mike:)

MarkB
01-04-2004, 01:56 PM
What about if you have something like:

$prevpage = $page - 1;
echo $prevpage;

or

$nextpage = $page + 1;
echo $nextpage;

(with the spaces)

Just a guess, but worth a shot... Getting the value of 'nextpage' before you echo it. I'm guessing (not being a PHP guru) that the echo statement is outputting each value as it comes to it, so it's seeing $page, echoing it, then seeing +1, and echoing the value of $page+1.

I am, of course, merely guessing.

Mike
01-04-2004, 02:05 PM
Sorry, doesn't work. Thanks anyway:)

Anyone got anymore ideas?

MarkB
01-04-2004, 02:14 PM
Does it do the same thing? Can you post your code?

Or look here for help: http://codewalkers.com/seecode/337.html

Just trying to help.

Mike
01-04-2004, 02:52 PM
Hi Mark, thanks for the link.

My code is as follows:



<?php
$var_array = explode("/",$REQUEST_URI);

$var = $var_array[2];

// if no page specified, start with page 1
if ($var == 0) { $page = 1; } else { $page = $var; }

//echo page links
if ($page != 1)
{
?>
<a href="<? echo $_SERVER['PHP_SELF']; ?><? echo $prevpage;
?>">Previous page</a> <? } ?> &nbsp; </td> <td align="center">Page <?
echo $page; ?> of <? echo $pageCount; ?></td> <td align="right"> &nbsp;
<? if ($page < $pageCount) { ?> <a href="<? echo $_SERVER['PHP_SELF'];
?><? echo $nextpage; ?>">Next page</a> <? } ?>


Thanks a lot,
Mike

chromate
01-04-2004, 03:03 PM
The problem is with your echo'ing of $_SERVER['PHP_SELF']

If you echo this only, you will see that it displays the full url (including the current page) and then you deduct 1 or add 1 and that too is echoed. So that's why you're getting the two numbers.

What you need to do is either grab the URL and remove the old page number that follows the last slash before echoing the new one. Or, as I would do, just echo a static url string and append the next page number to that.

ie... echo $view_items_url."/".$nextpage;

or something like that. :)

Mike
01-04-2004, 03:08 PM
Works a treat. Thanks very much chromate (how many times have I said that to you today;))

Thanks also for your efforts Mark...