can I pass a variable to a function using a hyperlink?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wilded1
Forum Newbie
Posts: 9
Joined: Sun Feb 21, 2010 11:49 am

can I pass a variable to a function using a hyperlink?

Post by wilded1 »

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.

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)
}
 
And this is the sort routine in a separate php script so I can use in with multiple tables.

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");
 
The variable are past with GET to the sort script like so for each column heading in the table:

Code: Select all

 
<th><a href="sortOrder.php?column=name&page=<?php echo $page;?>">Name</a>
 
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
wilded1
Forum Newbie
Posts: 9
Joined: Sun Feb 21, 2010 11:49 am

Sorted: can I pass a variable to a function using a hyperlin

Post by wilded1 »

Found an answer to this.
As soon as I'd written it down and looked at my own question it hit me.

Instead of sending the variables to a separate script, send by GET to the same page and check if the get isset.
If the get isset, then pass the variables to the function ......

Thanks for reading this.

Dave
Post Reply