I have a pagination inside an user profile.
When I’m inside the test profile the URL is profile.php?uid=1
But now I want to use a pagination to wiev the information from a SQL database.
When I try the pagination on another page it works fine, but as you know the pagination change the URL depends on what side your on.
So my problem is that the pagination change my profile.php?uid=1 to profile.php?page=2
Do you have any tips on how to fix that error ?
This is my pagination code.
/*pagination */
$per_page = 5;
//$pages_query = mysql_query("SELECT COUNT('user_id') FROM users");
$pages_query = mysql_query("SELECT COUNT('file_name') FROM users WHERE `user_name` = '{$_SESSION['username']}' ") or die(mysql_error());
$pages = ceil(mysql_result($pages_query, 0) /$per_page);
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start = ($page - 1) * $per_page;
<?php
$data = mysql_query("SELECT * FROM users LIMIT $start, $per_page")
or die(mysql_error());
echo "<table border cellpadding=1>";
while($info = mysql_fetch_array( $data ))
{ ?><?php
echo "<tr>";
// echo "<td>".$info['user_id'] . "</td> ";
echo "<td>".$info['user_name'] . "</td> ";
// echo "<td>".$info['file_name'] . "</td> ";
?>
<td> <a href="download.php?user_id=<?php echo $info['user_id'];?>"> <?php echo $info['file_name']; ?></a></td>
<?php
echo "<td>".date('d/m/Y') . "</td>" ;
}
echo "</tr>";
echo "</table>";
if($pages >= 1 && $page <=$pages){
for ($x = 1; $x<=$pages; $x++){
echo ($x == $page) ? '<strong><a href="?page='.$x.'">' .$x. '</a> </strong>' : '<a href="?page=' .$x. '">' .$x. ' </a> ';
}
}
?>
/*pagination */
And the profile
function fetch_user_info($uid){
$uid = (int)$uid;
$sql = "SELECT
`user_name` AS `username`,
`user_email` AS `email`
FROM `users`
WHERE `user_id` = {$uid} ";
$result = mysql_query($sql);
return mysql_fetch_assoc($result);
}
$data = mysql_query("SELECT * FROM users") or die(mysql_error());
$files = mysql_query("SELECT `file_name` FROM users WHERE `user_name` = '{$_SESSION['username']}' ") or die(mysql_error());
$user_info = fetch_user_info($_GET['uid']);
I really dont have a clue on how to fix this =/
Looks like you’re not passing the user id in your pager links, try changing this line…
to