Results 1 to 7 of 7

Thread: Weird Problem

  1. #1
    Registered Mike's Avatar
    Join Date
    May 2003
    Location
    UK
    Posts
    2,755

    Weird Problem

    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
    Don't you just love free internet games ?

  2. #2
    Web Monkey MarkB's Avatar
    Join Date
    Nov 2003
    Location
    London, UK
    Posts
    1,783
    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.
    Stepping On Wires - the new blog

  3. #3
    Registered Mike's Avatar
    Join Date
    May 2003
    Location
    UK
    Posts
    2,755
    Sorry, doesn't work. Thanks anyway

    Anyone got anymore ideas?
    Don't you just love free internet games ?

  4. #4
    Web Monkey MarkB's Avatar
    Join Date
    Nov 2003
    Location
    London, UK
    Posts
    1,783
    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.
    Stepping On Wires - the new blog

  5. #5
    Registered Mike's Avatar
    Join Date
    May 2003
    Location
    UK
    Posts
    2,755
    Hi Mark, thanks for the link.

    My code is as follows:

    PHP Code:
    <?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
    Don't you just love free internet games ?

  6. #6
    Senior Member chromate's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    2,348
    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.

  7. #7
    Registered Mike's Avatar
    Join Date
    May 2003
    Location
    UK
    Posts
    2,755
    Works a treat. Thanks very much chromate (how many times have I said that to you today)

    Thanks also for your efforts Mark...
    Don't you just love free internet games ?

Similar Threads

  1. viewing problem
    By fellboyzs in forum HTML, CSS, Layout, and Design
    Replies: 2
    Last Post: 05-05-2004, 06:15 PM
  2. preg Problem
    By Mike in forum Website Programming & Databases
    Replies: 3
    Last Post: 03-19-2004, 09:18 AM
  3. Search Engine Friendly URLs Problem
    By cameron in forum Search Engine Optimization
    Replies: 5
    Last Post: 02-24-2004, 08:43 PM
  4. Problem with my links
    By Mike in forum HTML, CSS, Layout, and Design
    Replies: 3
    Last Post: 11-15-2003, 03:25 PM
  5. My Problem
    By Chris in forum General Chat
    Replies: 10
    Last Post: 08-30-2003, 12:59 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •