What I want to do is get all of the members from a table in my database and sort it by a certain column. All that works perfectly, but I only want to display 20 users per page and I cant figure out how to set it up where it automatically detects how many users there are, divide that by 20, and have that many page links at the bottom of the table and have each page display the next 20 users.
PHP:
<?
// Get the name of the column to sort
$columnname = "alchemy";
if ($_GET['alchemy']) {
$columnname = $_GET['alchemy'];
}
// Get the value of either ascending or descending
$order = "";
if ($_GET['order']) {
$order = $_GET['order'];
}
// Display 20 records per page.
$display_number = 20;
// Make the calculation to see how many pages are there.
if (!isset($num_pages)) {
$query1 = "SELECT * FROM ".TBL_USERS."";
// Query the database.
$query_result1 = mysql_query ($query1) or die (mysql_error());
// Calculate the number of pages required.
$num_results = @mysql_num_rows ($query_result1);
if ($num_results > $display_number) {
$num_pages = $num_results/$display_number;
} elseif ($num_results > 0) {
$num_pages = 1;
}
// Currently at item 0.
$start = 0;
}
// Make the default column name
if ($columnname == "")
{$columnname = "username"; }
// Make the default order sorting
if ($order == "") {
$order = "DESC"; }
// Make the new, limited query.
$query = "SELECT * FROM ".TBL_USERS." ORDER BY $columnname $order LIMIT $start, $display_number";
// Print a table.
echo '<form action="main.php" method="post"> <br><table width="740" align="center" cellpadding="0" cellspacing="0" border="1">
<tr align="center">
<td width="300"><div align="center">
<font color="#ffffff" size="2" face="Verdana, Arial, Helvetica, sans-serif"><b>Username</b></font>
</div>
</td>
<td width="175"><div align="center">
<font color="#ffffff" size="2" face="Verdana, Arial, Helvetica, sans-serif"><b>Alchemy</b></font>
</div>
</td>
<td width="600"><div align="center">
<font color="#ffffff" size="2" face="Verdana, Arial, Helvetica, sans-serif"><b>Status</b></font>
</div>
</td>
</tr>';
// Print each item.
$query_result = @mysql_query ($query);
while ($row = @mysql_fetch_array ($query_result)) {
echo "<tr align=\"center\" bgcolor=\"$row[colourcode]\">
<td align=\"left\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\" > $row[username]</font></td>
<td align=\"left\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\" > $row[alchemy]</font></td>
<td align=\"left\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\" > $row[statetitle]</font></td>
</tr>";
}
?>