Jump to content

Pagination not working properly


Recommended Posts

i have this pagination code, that is ment to display 1 user per page, but it doesn't work, it shows all the usernames but has page 1-3 but they all show the same data. There is also a number 7 at the top of the area where the pagination is.

this is my pagination code,

if (!(isset($pagenum)))
{
$pagenum = 1;
} 
$data = mysql_query("SELECT * FROM $user") or die(mysql_error());
$rows = mysql_num_rows($data); 
$page_rows = 1;
$last = ceil($rows/$page_rows); 
if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
} 
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
$data_p = mysql_query("SELECT * FROM $user $max") or die(mysql_error());
while($info = mysql_fetch_array( $data_p ))
{
Print $info['user_id'];
echo "<br>";
}
echo "<p>";
echo " --Page $pagenum of $last-- <p>";
if ($pagenum == 1)
{
}
else
{
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> ";
echo " ";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> ";
} 
echo " ---- ";
if ($pagenum == $last)
{
}
else {
$next = $pagenum+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> ";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> ";
}

 

and this is where i tried implementing it

<?php
require_once 'includes/header.php';
require_once 'includes/db_connect.php';
?><div class="bg"></div>
<div class="clock"><?php echo gmdate('l, jS F Y');?> <span id="txt"></span></div> 
<div class="member">
<?php
if ($_SESSION['is_valid'] == true){

if (isset($_GET['id'])) {
if ((int) $_GET['id'] > 0) {
require_once 'nav_bar.php';

$userid = $_GET['id'];
$sql = "SELECT * FROM $user WHERE `user_id`='{$userid}' LIMIT 0,1;";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$userprofname = $row['user_name'];
$profemail = $row['user_email'];
echo "$userprofname";
$show_email = $row['show_email'];
if (mysql_num_rows($result) < 1) {
     echo 'This ID does not exist in the database<br>';
 echo "<a href=\"members.php\">Return to Members Page</a>";
 exit();
}
if ($show_email == 1)
{ 
echo '<br>Email:<a href="mailto:'.$profemail.'">    Email Me</a>';
}
elseif ($show_email == 0)
{
echo "<br>Email:   Hidden";
}
exit();
}
else {
echo "Unknown User ID! <br />";
echo "<a href=\"members.php\">Return to Members Page</a>";
exit();
}
}
//No ID passed to page, display user list:
$query = "SELECT user_id, user_name FROM $user";
$result = mysql_query($query) or die("Error:" . mysql_error());

if (mysql_num_rows($result) > 0) {
echo "User List:<br />";
while ($row = mysql_fetch_assoc($result)) {
  echo '<a href="?id=' . $row['user_id'] . '">' . $row['user_name'] . '</a><br />';
}
}
}
else
{
echo "Please login to view this page.";
}
?>
</div>
<?php
mysql_close();
require_once 'nav_bar.php';
require_once 'includes/footer.php';
?>

 

this is the exact area

//No ID passed to page, display user list:
$query = "SELECT user_id, user_name FROM $user";
$result = mysql_query($query) or die("Error:" . mysql_error());

if (mysql_num_rows($result) > 0) {
echo "User List:<br />";
while ($row = mysql_fetch_assoc($result)) {
  echo '<a href="?id=' . $row['user_id'] . '">' . $row['user_name'] . '</a><br />';
}
}
}

 

if i'm not explaining properly just say

Link to comment
https://forums.phpfreaks.com/topic/104123-pagination-not-working-properly/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.