Previous and Next

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Previous and Next

Post by icesolid »

The code below is not working for me on this new server, but on another server the same code works, do I need to change how I call my variables?

My problem is basically when you click the "Next 5 Users" it does not reconize that $offset has changed, the program still reconizes $offset as 0.

Code: Select all

<table width="350" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center">CHANGE USER INFORMATION</td>
  </tr>
  <?php
  if($offset == "") {
      $offset = "0";
  }

  $limit = "5";
  $result = mysql_query("SELECT * FROM users ORDER BY id DESC LIMIT $offset,$limit");

  while($row = mysql_fetch_array($result)) {
  ?>
  <form method="post" action="executive.php?cmd=change_a_user">
  <input type="hidden" name="id" value="<?php echo $row["id"]; ?>">
  <tr>
    <td><?php echo $row["username"]; ?></td>
    <td><input type="submit" name="change" value="Change" class="buttons"></td>
  </tr>
  </form>
  <?php
  }
  ?>
  <tr>
  <?php
  if($offset == "0") {
  ?>
    <td>&laquo; Previous 5 Users</td>
  <?php
  } else {
  ?>
    <td>&laquo; <a href="executive.php?cmd=change_a_user&limit=<?php echo $limit; ?>&offset=<?php echo $offset - "5"; ?>">Previous 5 Users</a></td>
  <?php
  }

  if(mysql_num_rows($result) == $row["id"]) {
  ?>
    <td>Next 5 Users &raquo; </td>
  <?php
  } else {
  ?>
    <td><a href="executive.php?cmd=change_a_user&limit=<?php echo $limit; ?>&offset=<?php echo $limit + "5"; ?>">Next 5 Users</a> &raquo;</td>
  <?php
  }
  ?>
  </tr>
</table>
Last edited by icesolid on Mon Mar 06, 2006 3:33 pm, edited 2 times in total.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

where's $offset coming from?

if it's coming from the URL it will need to be $_GET['offset']; as the server you're using most likely doesn't have register_globals() on.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply