can I pass a variable to a function using a hyperlink?
Posted: Wed Feb 24, 2010 3:53 am
Hi.
At the moment I am sorting a table list using a hyperlink in the TH of the table that passes the page to return to after the sort routine and the column name. the php sets cookies to perform the ordering of the table.
This is the set-up in the page with the table.
And this is the sort routine in a separate php script so I can use in with multiple tables.
The variable are past with GET to the sort script like so for each column heading in the table:
What I would like is to have the sort routine in my function script with the rest of the functions rather than it being a stand alone script and pass the variables to the function from the url in the table column heading or by some other method.
I would be grateful for any advice.
TIA
Dave
At the moment I am sorting a table list using a hyperlink in the TH of the table that passes the page to return to after the sort routine and the column name. the php sets cookies to perform the ordering of the table.
This is the set-up in the page with the table.
Code: Select all
$page = "multiTrust"; // the filename of this page without the php extension
$column = "zonerp_cs"; // our default sort column
$order = "ASC"; // The default sort order
########################
// Check if we have selected a different column to sort the table by
if (isset($_COOKIE['column'])){
$column = $_COOKIE['column']; // Our chosen sort column (if set).
}
// Check if we have selected a different sort order for our chosen column
if (isset($_COOKIE['direction'])){
$order = $_COOKIE['direction']; // Our chosen direction to order a column (if set)
}
Code: Select all
// Sort by column and order ASC/DESC
$orderby = $_GET['column'];
$page = $_GET['page'];
setcookie ('column', $orderby);
// set order by
if($_COOKIE['direction'] != 'ASC'){
setcookie ('direction', 'ASC');
}
else {
setcookie ('direction', 'DESC');
}
// Reload page
header ("Location: ".$page.".php");
Code: Select all
<th><a href="sortOrder.php?column=name&page=<?php echo $page;?>">Name</a>
I would be grateful for any advice.
TIA
Dave