my idea is like this i have this table in receive.php after getting $_POST['acc_no'] $_POST['acc_holder'] $_POST['amount'] from a page say start.php. using these data I am able to get this table querying it from MySQL database | Account No | Holder Name | Amount | | 2331 | John Doe | $400 | | 2332 | Amanda Jack| $350 | | 2333 | Ahmed Rio | $700 | | 2334 | Mary Jane | $640 | I want the title on each column to be a hyperlink so that user able to click on each column title and sort the data accordingly. Eg. When a user click on holder name receive.php will sort the data in the table like this and be displayed in receive.php too | Account No | Holder Name | Amount | | 2333 | Ahmed Rio | $700 | | 2332 | Amanda Jack| $350 | | 2331 | John Doe | $400 | | 2334 | Mary Jane | $640 | and if the user want to sort by Amount just click the title Amount and it will be sorted by Amount how can this be done?
You links will look something like: <a href="receive.php?orderby=account">Account No</a> You then write your POSTS to a cookie value or include them in the get link. Then you add this if statement to your code $orderby=""; if ($_GET["orderby"]) { $fieldname = $_GET["orderby"]; $orderby = "ORDER BY $fieldname"; } PHP: Then Include $oderby in your mysql "SELECT * FROM Blah where blah = 'blah' $oderby" If there is not $_GET then that last part will be blank and ignored. Hope that helps
Avoid using $_GET["orderby"] right into your SQL query string. It's dangerous. <a href="receive.php?orderby=C1">Account No</a> switch($_GET["orderby"]) { case 'C1': $orderby = "ORDER BY account" break; case 'C2': $orderby = "ORDER BY holder" break; case 'C3': $orderby = "ORDER BY amount" break; } PHP: