So I have a php/mySQL sortable table, but to the right of the links that sort the table i want little arrow graphics that show the user whether they are sorting the list by ASC or DESC where and how do i put the code for the graphics
thanks kevin
here is the php code:
<?php
// This script retrieves all the records from the model_list table.
// This script paginates the query results.
// This script sorts the query results.
require_once (); // Connect to the db.
// Number of records to show per page:
$display = 10;
// Determine how many pages there are.
if (isset($_GET[‘np’])) { // Already been determined.
$num_pages = $_GET[‘np’];
} else { // Need to determine.
// Count the number of records
$query = “SELECT COUNT(*) FROM model_list ORDER BY model_name ASC”;
$result = mysql_query ($query);
$row = mysql_fetch_array ($result, MYSQL_NUM);
$num_records = $row[0];
// Calculate the number of pages.
if ($num_records > $display) { // More than 1 page.
$num_pages = ceil ($num_records/$display);
} else {
$num_pages = 1;
}
} // End of np IF.
// Determine where in the database to start returning results.
if (isset($_GET[‘s’])) {
$start = $
} else {
$start = 0;
}
//Default column links.
$link1 = “{$_SERVER[‘PHP_SELF’]}?sort=mna”;
$link2 = “{$
$link3 = “{$_SERVER[‘PHP_SELF’]}?sort=batha”;
$link4 = “{$
//Determine the sorting order
if (isset($_GET[‘sort’])) {
//Use existing sorting order.
switch ($_GET[‘sort’]) {
case ‘mna’:
$order_by = ‘model_name ASC’;
$link1 = “{$_SERVER[‘PHP_SELF’]}?sort=mnd”;
break;
case ‘mnd’:
$order_by = ‘model_name DESC’;
$link1 = “{$_SERVER[‘PHP_SELF’]}?sort=mna”;
break;
case ‘beda’:
$order_by = ‘bedrooms ASC’;
$link2 = “{$_SERVER[‘PHP_SELF’]}?sort=bedd”;
break;
case ‘bedd’:
$order_by = ‘bedrooms DESC’;
$link2 = “{$_SERVER[‘PHP_SELF’]}?sort=beda”;
break;
case ‘batha’:
$order_by = ‘baths ASC’;
$link3 = “{$_SERVER[‘PHP_SELF’]}?sort=bathd”;
break;
case ‘bathd’:
$order_by = ‘baths DESC’;
$link3 = “{$_SERVER[‘PHP_SELF’]}?sort=batha”;
break;
case ‘sfa’:
$order_by = ‘square_footage ASC’;
$link4 = “{$_SERVER[‘PHP_SELF’]}?sort=sfd”;
break;
case ‘sfd’:
$order_by = ‘square_footage DESC’;
$link4 = “{$_SERVER[‘PHP_SELF’]}?sort=sfa”;
break;
}
//Sort will be appended to the pagination links
$sort = $_GET[‘sort’];
} else { //Use the default sorting order.
$order_by = ‘model_name ASC’;
$sort = ‘mna’;
}
// Make the query.
$query = “SELECT model_id, model_url, model_name, bedrooms, baths, square_footage, model_pic FROM model_list ORDER BY $order_by LIMIT $start, $display”;
$result = mysql_query ($query); // Run the query.
// Table header.
echo'<table id=”model_table” cellspacing=”0″>
<tr>
<th scope=”col”><b></b></th>
<th scope=”col”><b><a href=”‘ . $link1 . ‘”>Model Name</a></b></th>
<th scope=”col”><b><a href=”‘ . $link2 . ‘”>Bedrooms</a></b></th>
<th scope=”col”><b><a href=”‘ . $link3 . ‘”>Baths</a></b></th>
<th scope=”col”><b><a href=”‘ . $link4 . ‘”>Square Feet</a></b></th>
<th scope=”col”><b></b></th>
</tr>
‘;
// Fetch and print all the records.
$bg = ‘#eeeeee’; // Set the background color.
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$bg = ($bg==’#CDD2C8′ ? ‘#BBC2B4’ : ‘#CDD2C8’); // Switch the background color.
echo'<tr bgcolor=”‘ . $bg . ‘”>
<td>’ . $row[‘model_pic’] . ‘</td>
<td>’ . $row[‘model_name’] . ‘</td>
<td>’ . $row[‘bedrooms’] . ‘</td>
<td>’ . $row[‘baths’] . ‘</td>
<td>’ . $row[‘square_footage’] . ‘</td>
<td><a href=”
</tr>
‘;
}
echo'</table>’;
mysql_free_result ($result); // Free up the resources.
mysql_close(); // Close the database connection.
// Make the 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, make a Previous button.
if ($current_page != 1) {
echo ‘<a href=”ModelHomes.php?s=’ . ($start – $display) . ‘&np=’ . $num_pages . ‘&sort=’ . $sort . ‘”>Previous</a> ‘;
}
// Make all the numbered pages.
for ($i = 1; $i <= $num_pages; $i++) {
if ($i != $current_page) {
echo ‘<a href=”ModelHomes.php?s=’ . (($display * ($i – 1))) . ‘&np=’ . $num_pages . ‘&sort=’ . $sort . ‘”>’ . $i . ‘</a> ‘;
} else {
echo $i . ‘ ‘;
}
}
// If it’s not the last page, make a Next button.
if ($current_page != $num_pages) {
echo ‘<a href=”ModelHomes.php?s=’ . ($start + $display) . ‘&np=’ . $num_pages . ‘&sort=’ . $sort . ‘”>Next</a>’;
}
echo ‘</p>’;
} // End of links section.
?>