Posted: Sun Nov 07, 2004 7:55 am Post subject: Need Help Sorting Table Columns with Database Fields
If you look at my page at http://www.geoworld.org/reference/people/ you'll see a table with a PHP script that gives it sortable columns. Suppose I modified this table so that only the FIRST column was displayed. Could the PHP script be modified so that you could still choose "Population" and the table would be rearranged by population, even though the Population column isn't visible? In other words, I'd like to be able to sort by database table fields, whether those fields are displayed as columns on my page or not.
If so, how should I modify the script below? Thanks.
$result = mysql_query('select count(*) from cia_people');
if (($result) && (mysql_result ($result , 0) > 0)) {
// continue here with the code that starts
//$res = mysql_query ("SELECT * FROM type.....
} else {
die('Invalid query: ' . mysql_error());
}
{
$order = isset($_REQUEST['order']) ? intval($_REQUEST['order']) : 0;
switch($order)
{
case 1:
$order = 'Name';
break;
case 2:
$order = 'Pop';
break;
case 3:
$order = 'Nationality';
break;
case 4:
$order = 'NationalityPlural';
break;
case 5:
$order = 'NationalityAdjective';
break;
case 6:
default:
$order = 'Name';
break;
}
if (isset($_REQUEST['direction']) && intval($_REQUEST['direction'])) {
// if (isset($_REQUEST['direction']) && intval($_REQUEST['direction'])) {
$direction = ' DESC';
} else {
$direction = '';
}
$res = mysql_query('SELECT IDArea, Name, Pop, Nationality, NationalityPlural, NationalityAdjective
FROM cia_people as c
WHERE c.Nationality is not null
ORDER BY c.' . $order . $direction);
[quote="papercrane"]Just don't display the other columns.....I don't see why you're having a problem with this. Remove them from the SELECT and remove their TD entries.[/quote]
OK, problem solved. I had tried your suggestion earlier without success, but I just discovered a stupid mistake I made.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum