Pagination - Driving Me Insane
Posted: Sat Mar 17, 2012 7:29 pm
I'm ready to pull my hair out. *frustrated face*.
My problem is that I have multiple fields in my table and I want to display them in the pagination. Instead of just having "username" like in the tutorial, I want "username" and "bio".
Can anyone help? Here's my code:
My problem is that I have multiple fields in my table and I want to display them in the pagination. Instead of just having "username" like in the tutorial, I want "username" and "bio".
Can anyone help? Here's my code:
<?php include ('config.php'); if (isset($_SESSION['user_id'])) { $page = (isset($_GET['page'])) ? $_GET['page'] : 1; $limit = 3; $sql = mysql_query("SELECT * FROM `users`"); ?> <table> <tr> <th>Username</th> <th>Website</th> </tr> <?php foreach (fetchUsers($page, $limit) as $user) { ?> <tr> <td><?php echo $user; ?></td> <td>Joined</td> </tr> <?php } ?> </table> <?php $pages = ceil(fetchTotalusers() / $limit); echo '<br />'; for ($i = 1; $i <= $pages; ++$i) { echo ' <a href="?page='.$i.'">'.$i.'</a> '; } } else { loginForm(); } ?>The function:
function fetchUsers($page, $per_page) { $start = ($page -1) * $per_page; $per_page = $per_page; $query = mysql_query("SELECT * FROM `users` LIMIT $start, $per_page"); while ($row = mysql_fetch_assoc($query)) { $users[] = $row['user_username']; $date = date("D M d, Y",$row['user_joined']); } return $users; }