简体   繁体   中英

How to create a button to sort date in ascending and descending?

Activation Date Hi, I am having trouble with arranging my Date from ascending to descending and vice versa. So I have a column called Activation Date, and I want it to be able to arrange the column when the table head "Activation Date" is clicked. I am using data from my database.

  echo "<th><a href='sortDate.php?member={$brokerName}&memberid={$brokerID}&sort=asc' class='btn btn-sm' role='button'>Activation Date</a></th>"

The above is the code for the Activation Date. Basically I put the link to return user back to the same page, with the intend of displaying the column either in descending or ascending order.

For the sortDate.php, I used the select statement from my database to order the column to ASC and DESC depending on the value of the page. However, when I try it, it just keeps returning me to the same page with no changes.

if ($sort == 'asc') {
$sql = "SELECT * FROM applicantdetails WHERE EmployeeID={$brokerID} ORDER BY ActivationDate DESC";
mysqli_query($con, $sql);
header("Location: brokerDetailTest.php?member={$brokerName}&memberid={$brokerID}"); } else {
$sql = "SELECT * FROM applicantdetails WHERE EmployeeID={$brokerID} ORDER BY ActivationDate ASC";
mysqli_query($con, $sql);
header("Location: brokerDetailTest.php?member={$brokerName}&memberid={$brokerID}");}

You should use the $_GET array to "get" the information from the url. You used sort='asc' in your url. SO use something like this. I think for the sorting REVERSED ASC AND DESC in your query

    $sort = (isset($_GET['sort'])) ? $_GET['sort'] : null ;

    //for the ASC part
    if ($sort == 'asc') 
    {
    }
    //DESC part
    else{

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM