I am initializing the session variable on the page before I want to perform sorting, and I am using the onclick event attribute to set the value of the session variable. The session variable is misbehaving and is not working as intended. Upon refreshing the page, or clicking either the ID link or Name link, the session variable is getting set to value 2, whereas ideally if I click on ID link, it should set to value "1" and sort by ID and not name.
Here is the code snippet that I am using:
Use of session variable:
if (($_SESSION['sortby'] <> 2))
{ array_multisort($array_nid, $array_name, $array_id, $enable);}
elseif ($_SESSION['sortby'] == 2)
{ array_multisort($array_name, $array_nid, $array_id, $enable);}
Definition of session variable:
<tr>
<td><a href="home.php" onclick="<?php $_SESSION['sortby'] = 1;?>">ID[/url]<img src="images/sort_arrow.jpg" width="10px" height="10px"></td>
<td valign="top"><a href="home.php" onclick="<?php $_SESSION['sortby'] = 2;?>">Nugget Name[/url]<img src="images/sort_arrow.jpg" width="10px" height="10px"></td></tr>
Note, the table is for formatting purposes only. Does the onclick even attribute doesn't support this kind of functionality?
Kindly help, urgently.
Thanks a lot.