Jump to content

[SOLVED] page count


dare87

Recommended Posts

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();
			?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.