Hi,
I would like to have the following script return results with the results grouped alphanumerically within the category, for example; 0-1, 2-3, 4-5, 6-7, 8-9, A-B, CD, EF, GH, IJ, KL, MN, OP, QR, ST, UV, WX, YZ.
The current script returns the results alphanumerically within the category but doesn't group the results. How can I achieve this?
Here's the code:
<?php # PHP Script
$page_title = 'Gigidig California';
include ('./header.inc');
// Use the HTML header file.
require_once ('/.../.../.../.../mysql_connect.php');
//Connect to the db.
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" align="center">
<!-- START OF DYNAMIC MULTI COLUMN DISPLAY -->
<?php # PHP Script - display.php
// Number of records to display per page:
$display = 100;
// Determine how many pages there are.
if (isset($_GET['np'])) { //Already been determined.
$num_pages = $_GET['np'];
} else { // Need to determine.
//get the data
$query = "SELECT purchase_date, web_site, link_text, paid, category, subcategory, region, state, country, worldwide FROM advertisers WHERE paid = 1 ORDER BY category, subcategory, link_text";
$query_result = mysql_query($query);
$num_records = @mysql_num_rows ($query_result);
if ($num_records > $display) { // More than 1 page.
$num_pages =ceil ($num_records/$display);
} else {
$num_pages = 1;
}
}
// Determine where in the database to start returning results.
if (isset($_GET['s'])) { // Already been determined.
$start = $_GET['s'];
} else {
$start = 0;
}
// Make the query.
$query = "SELECT purchase_date, web_site, link_text, paid, category, subcategory, region, state, country, worldwide FROM advertisers WHERE paid = 1 ORDER BY category, subcategory, link_text LIMIT $start, $display";
$result = @mysql_query($query); // Run the query.
$num = mysql_num_rows ($result); // How many records are there?
if ($num > 0) { // If it ran ok, display the records.
// Make the links to other pages, if necessary.
if ($num_pages > 1) {
// Determine what page the script is on.
$current_page = ($start/$display) + 1;
// If it's not the first page, make a Previous button.
if ($current_page != 1) {
echo '<div align="center"><a href="category.php?s=' . ($start - $display) . '&np=' . $num_pages . '"><font face="arial" size="2"><b>Previous</b></font></a> ';
}
// Make all the numbered pages.
for ($i = 1; $i <= $num_pages; $i++) {
if ($i != $current_page) {
echo '<a href="category.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '"><font face="arial" size="2"><b>' . $i . '</b></font></a> ';
} else {
echo $i . ' ';
}
}
// If it's not the last page, make a next button.
if ($current_page != $num_pages) {
echo '<a href="category.php?s=' . ($start + $display) . '&np' . $num_pages . '"><font face="arial" size="2"><b>Next</b></font></a>';
}
echo '</div>';
} // End of links section.
}
echo '</tr>';
echo '</table>';
echo '<table>';
echo '<tr>';
echo '<td valign="top" align="left" width="20%"><blockquote><font face="arial" size="2"><b>Category</b></font></blockquote></td>';
echo '<td valign="top" align="left" width="20%"><font face="arial" size="2"><b>Sub-Category</b></font></td>';
echo '<td valign="top" align="left" width="40%"><font face="arial" size="2"><b>Web Site</b></font></td>';
echo '<td valign="top" align="left" width="10%"><font face="arial" size="2"><b>Date Published</b></font></td>';
echo '</tr>';
echo '<tr>';
//set variables and constants.
DEFINE('NUM_COLUMNS', 1);
DEFINE('TABLE_WIDTH', 900);
$record_number = 0;
$column_width = floor(TABLE_WIDTH / NUM_COLUMNS);
echo '<table align="center" width="'. TABLE_WIDTH . '" border="0" cellspacing="0" cellpadding="0">';
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
if(fmod($record_number, NUM_COLUMNS) == 0)
echo '<tr>';
//--information for each individual cell in the row
echo '<td valign="top" align="left">';
echo '<br>';
echo '<font face="arial" size="2">' . $row[4] . '</b></font>';
echo '<br>';
echo '</td>';
echo '<td valign="top" align="left">';
echo '<br>';
echo '<font face="arial" size="2">' . $row[5] . '</b></font>';
echo '<br>';
echo '</td>';
echo '<td valign="top" align="left">';
echo '<br>';
echo '<font face="arial" size="2"><a href="' . $row[2] . '" target="_blank"><b>' . $row[2] . '</b></a></font>';
echo '<br>';
echo '</td>';
echo '<td valign="top" align="left">';
echo '<br>';
echo '<font face="arial" size="2">' . $row[0] . '</font>';
echo '<br>';
echo '</td>';
//---
$record_number++;
if(fmod($record_number, NUM_COLUMNS) == 0)
echo '</tr>';
}
echo '</table>';
?>
<!-- END OF DYNAMIC MULTO COLUM DISPLAY -->
</td>
</tr>
</table>
<?php
include ('footer.inc');
mysql_close(); // Close the database connection.
?>