Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 998997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:17:05+00:00 2026-05-16T07:17:05+00:00

I know it’s such a basic thing, but a Google search hasn’t shown me

  • 0

I know it’s such a basic thing, but a Google search hasn’t shown me how to re-sort the rows after clicking the th links.

I’ve got this:

<table border="1">
  <tr>
    <th>Type:</th>
    <th>Description:</th>
    <th>Recorded Date:</th>
    <th>Added Date:</th>
  </tr>

<?php 
while($row = mysql_fetch_array($result)){
    ?>
    <tr>
        <td><?php echo $row['type'] ?></td>
        <td><?php echo $row['description'] ?></td>
        <td><?php echo $row['recorded_date'] ?></td>
        <td><?php echo $row['added_date'] ?></td>
    </tr>
    <br /> 


  <?php 
}
mysql_close();
?>
</table>

I need to be able to click type and sort alphabetically, and click on either Recorded Date or Added Date and sort by date. I see that I need to have the MySQL queries do this, but do I set them up as conditionals with a href tags?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:17:05+00:00Added an answer on May 16, 2026 at 7:17 am

    The easiest way to do this would be to put a link on your column headers, pointing to the same page. In the query string, put a variable so that you know what they clicked on, and then use ORDER BY in your SQL query to perform the ordering.

    The HTML would look like this:

    <th><a href="mypage.php?sort=type">Type:</a></th>
    <th><a href="mypage.php?sort=desc">Description:</a></th>
    <th><a href="mypage.php?sort=recorded">Recorded Date:</a></th>
    <th><a href="mypage.php?sort=added">Added Date:</a></th>
    

    And in the php code, do something like this:

    <?php
    
    $sql = "SELECT * FROM MyTable";
    
    if ($_GET['sort'] == 'type')
    {
        $sql .= " ORDER BY type";
    }
    elseif ($_GET['sort'] == 'desc')
    {
        $sql .= " ORDER BY Description";
    }
    elseif ($_GET['sort'] == 'recorded')
    {
        $sql .= " ORDER BY DateRecorded";
    }
    elseif($_GET['sort'] == 'added')
    {
        $sql .= " ORDER BY DateAdded";
    }
    
    $>
    

    Notice that you shouldn’t take the $_GET value directly and append it to your query. As some user could got to MyPage.php?sort=; DELETE FROM MyTable;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 507k
  • Answers 507k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can cut out the strings: from lxml.html import HtmlComment… May 16, 2026 at 4:08 pm
  • Editorial Team
    Editorial Team added an answer The latest drop of the open source Extended WPF Toolkit… May 16, 2026 at 4:08 pm
  • Editorial Team
    Editorial Team added an answer You are not putting a " before the end of… May 16, 2026 at 4:08 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Know this might be rather basic, but I been trying to figure out how
know nothing about php, but I have this script that reads a folder and
I know in certain circumstances, such as long running processes, it is important to
I know this is a stupid question, but I can't find the answer anywhere.
I know similar questions have been posted before, but I have specific requirements that
I know I can remove the last element from a set: s.Remove(s.MaximumElement) But if
I know these are the basics of rails but i still don't know the
I know, I know, IE6 is the devil but I have no choice but
I know this is a silly doubt but I just want to make sure
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.