PHP pagination and IDs


PHP pagination and IDs

我非常需要你的帮助。我正在创建一个页面,该页面将使用分页显示所有注册成员的列表,但当我单击任何用户时,它只会将我带到"profile.php"?user=3'而不是用户的id配置文件如果你理解我的意思,请告诉我我在编码中做错了什么:

    <html>
<head>
<title>MEMBERS</title>
<link rel="icon" href="guyt.gif" type="image/x-icon">
<link rel="stylesheet" type="text/css" media="all" href="style.css">
</head>
<body>
<?php include 'connect.php'; ?>
<?php include 'functions.php'; ?>
<?php include 'header.php'; ?>
<div id="sidebar">
<br>
<?php include 'lists.php'; ?>
</div>
</body>
</html>

这是lists.php,它包含分页:

    <?php
$per_page = 5;
if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page = $_GET['page'];
}
if($page<=1)
$start = 0;
else
    $start = $page * $per_page - $per_page;
    $mem_query = mysql_query("SELECT id FROM register");
    while($run_mem = mysql_fetch_array($mem_query)){
        $id = $run_mem['id'];
        $first = getuser($id, 'first');
        $last = getuser($id, 'last');
    }

$sql = "SELECT * FROM register";
$num_rows = mysql_num_rows(mysql_query($sql));
$num_pages = ceil($num_rows / $per_page);

$sql .= " LIMIT $start, $per_page";
$result = mysql_query($sql);
While($row = mysql_fetch_array($result)){
        echo "<div class='header'><table width='98%'><tr><td><div align='left'>" . $row['first'] . " " . $row['last'] . "</div></td><td><div align='right'><a href='profile.php?user=$id'>VISIT PROFILE</a></div></td></tr></table></div><br>";
    }
$prev = $page - 1;
$next = $page + 1;
echo "<hr>";
if($prev > 0)
echo "<a href='?page=$prev' class='box'>Previous</a></font> ";
if($page < ceil($num_rows/$per_page))
echo " <a href='?page=$next' class='box'>Next</a></font>";

?>
Please look at your code critically,you are generating the id within the first loop and assigning the value in the second loop. That is your problem,because after the execution of first loop the variable id will be assigned to the last member id which is basically 3. It will also be nice to show the profile.php.
Solution
change your url to this
<a href='profile.php?user='.$row['id']>VISIT PROFILE</a>