PDA

View Full Version : How to modify columns after they have been set?


kestrel7
11-11-2002, 09:44 PM
I want to enable the user to change a table gnereted by a sql query in the following ways.

1) To re-order the table according to a particular column by clicking on a column header which is a hyperlink.

So say there is a table generated by sql like this:

SELECT id, name, age FROM cust

if the user clicks on 'name' the table, should be changed to reflect the result of:

SELECT id, name, age FROM cust ORDER BY name

(and the same for id, age etc).

2) I want to allow the user to select columns to show/hide.
Say the orginal query is:

SELECT id, name, age FROM cust

Then I want checkboxes for each of the attributes in the select list and allow the user to select only the columns that they want to see (before resubmitting the form)

Thanks in advance for any help!

bcarl314
11-13-2002, 04:55 PM
Well assuming your using php try this:

$sql='';
if(isset($_GET['order'])) {
$sql = "SELECT id, name, age FROM cust ORDER BY $_GET[order]";
}
else {
$sql="SELECT id, name, age FROM cust";
}

then in your databse connection do

mysql_query($sql,$linkID);

where $linkID=is your database handle
in your HTML you'll need something like
<a href="my_php.php?order=name">Name</a>

kestrel7
11-13-2002, 05:04 PM
Thanks for the help bcarl314 . I tried it and it worked 100% !!

Thanks again! :thumbsup: