khanuja.sunpreet Posted March 4, 2008 Share Posted March 4, 2008 I need help. I am trying to sort records in PHP using array_multisort. The sort as such works just fine. I am trying to implement a table column header sort where clicking on the ID header would sort the records by ID and clicking on Name would sort the records by name. I am currently using session variables to maintain a numeric flag for sorting 1-for sorting on ID and 2-for sorting on Name. 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</a><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</a><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. Quote Link to comment https://forums.phpfreaks.com/topic/94193-help-needed-urgent/ Share on other sites More sharing options...
sasa Posted March 4, 2008 Share Posted March 4, 2008 session is on the server you can't change with javascrip use get method Quote Link to comment https://forums.phpfreaks.com/topic/94193-help-needed-urgent/#findComment-482542 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.