dare87 Posted May 15, 2008 Share Posted May 15, 2008 I have this code that is set to count how many records there are and then display them in sets of 25. It was working great until I hit over 100 records. It is now not making the page count for all the records. Any Ideas. <?php // Connect to the database. require_once ('../../mysql_connect.php'); // The number of pages to display per page. $display = 25; // Calculate how many pages will be needed. // If the number of pages has not been calculated, then it will need to calculated. if (isset($_GET['np'])) $num_pages = $_GET['np']; else // Needs to be calculated. { // Count the number of records in the database. $query = "SELECT COUNT(*) FROM users WHERE active IS NULL and access_level >=1"; $result = mysql_query ($query); $row = mysql_fetch_array ($result, MYSQL_NUM); $num_records = $row[0]; // Calculate the number of pages to use. if ($num_records > $display) $num_pages = ceil ($num_records / $display); else $num_pages = 1; } // Determine in the database to start returning results. if (isset($_GET['s'])) $start = $_GET['s']; else $start = 0; // Make the query. $query = "SELECT user_id AS id, email, user_name AS user, first_name AS first, last_name AS last, address, city, state, zip, phone, access_level AS level, DATE_FORMAT(date_registered, '%M %d, %Y') AS date FROM users WHERE access_level >=1 ORDER BY date_registered ASC LIMIT $start, $display"; // Run the query. $result = @mysql_query ($query); // If the query ran w/o error, print out the results. if ($result) { // Table header. echo ' <table width="100%" align="center" cellspacing="0" cellpadding="5"> <tr> <td align="left"><b> </b></td> <td align="left"><b> </b></td> <td align="left"><b>User Name</b></td> <td align="left"><b>Email</b></td> <td align="left"><b>Date Registered</b></td> </tr>'; // Fetch and print all the records. $bg = '#dee4ed'; // Set the background color. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { // Alternate the background color. $bg = ($bg == '#dee4ed' ? '#ffffff' : '#dee4ed'); echo ' <tr bgcolor="' . $bg . '"> <td align="left"><a href="user_edit.php?username=' . $row['user'] . '&last=' . $row['last'] . '&id=' . $row['id'] . '">Edit</a></td> <td align="left"><a href="auxiliary/user_delete.php?id=' . $row['id'] . '" onClick="return sure()">Delete</a></td> <td align="left">' . $row['user'] . '</td> <td align="left">' . $row['email'] . '</td> <td align="left">' . $row['date'] . '</td> </tr>'; } // Close the table. echo '</table>'; // Free up the resources. mysql_free_result ($result); // Make links to other pages, if necessary. if ($num_pages > 1) { echo '<br /><p>'; // Determine what page the script is on. $current_page = ($start / $display) + 1; // If it's not the first page, create a previous button. if ($current_page != 1) echo '<a href="user_review.php?s=' . ($start - $display) . '&np=' . $num_pages . '">Previous</a> '; // Make all the numbered pages. for ($i = 1; $i <= $num_pages; $i++) if ($i != $current_page) echo '<a href="user_review.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '">' . $i . '</a> '; else echo $i . ' '; // If it's not the last page, make a Next button. if ($current_page != $num_pages) echo '<a href="user_review.php?s=' . ($start + $display) . '&np=' . $num_pages . '">Next</a> '; echo '</p>'; } } else { // If the query did not run successfully, print out an error message. echo 'The User List could not be retrieved.'; } // Close the database connection. mysql_close(); ?> Quote Link to comment Share on other sites More sharing options...
gizmola Posted May 15, 2008 Share Posted May 15, 2008 What exactly happens now that there's +100 rows? Did you try putting in some debug comments for some of the key variables, and question your assumptions? Quote Link to comment Share on other sites More sharing options...
nloding Posted May 15, 2008 Share Posted May 15, 2008 If I can't find where's it's dying, I'll put little things like: echo "Just finished this process, here's this variable: " . $variable; And run it again. Also take the "@" off your query so you don't suppress anything while debugging. What's your output? Quote Link to comment Share on other sites More sharing options...
dare87 Posted May 16, 2008 Author Share Posted May 16, 2008 It works. It just doesn't show all the pages. Example you get to page 6 and there should be seven, but the next button is not there. If you type 7 up in the url it will show it though. Any ideas? Quote Link to comment Share on other sites More sharing options...
gizmola Posted May 19, 2008 Share Posted May 19, 2008 So it sounds like you know where to look for you error: in the routine that determines whether or not to display the next button. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.