Jump to content

Help Needed Urgent


Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/94193-help-needed-urgent/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.