Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. sorting on cloumn headers acending and desanding

sorting on cloumn headers acending and desanding

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
phpalgorithmstutorial
5 Posts 4 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    umeshdaiya
    wrote on last edited by
    #1

    hi i would like to know how to sort my dynamic generated table in php when i click on any header row on first click sort acending and on another click sort on decending order. :-D

    M J R 3 Replies Last reply
    0
    • U umeshdaiya

      hi i would like to know how to sort my dynamic generated table in php when i click on any header row on first click sort acending and on another click sort on decending order. :-D

      M Offline
      M Offline
      Mohammad Dayyan
      wrote on last edited by
      #2

      If you wanna sort Mysql Data, you should use two difference Mysql Query. For example :

      SELECT * FROM table1 ORDER BY filed ASC
      SELECT * FROM table1 ORDER BY filed DESC

      Else if you wanna sort a table in client you should use JavaScript.

      U 1 Reply Last reply
      0
      • M Mohammad Dayyan

        If you wanna sort Mysql Data, you should use two difference Mysql Query. For example :

        SELECT * FROM table1 ORDER BY filed ASC
        SELECT * FROM table1 ORDER BY filed DESC

        Else if you wanna sort a table in client you should use JavaScript.

        U Offline
        U Offline
        umeshdaiya
        wrote on last edited by
        #3

        ya i know these are two commands to show asc and desc but i would like to know that i have a grid table in php and on every field i want to do this and show a image full process to do this this grid is filled by while loop as used in php all dataare there but i want to show sorting on header of the fields click. thanks for reply :-D

        1 Reply Last reply
        0
        • U umeshdaiya

          hi i would like to know how to sort my dynamic generated table in php when i click on any header row on first click sort acending and on another click sort on decending order. :-D

          J Offline
          J Offline
          Jules VDV
          wrote on last edited by
          #4

          I think you want to load a table and then be able to sort the data by a column after the data is loaded by clicking on the col header, correct? Uh oh, i think i may like jQuery too much as i just posted a different response pointing the user to the jQuery library. Take a look at ajaxrain.com for table plugins to jQuery. I know there's a couple of them out there, if this is what you're looking for

          1 Reply Last reply
          0
          • U umeshdaiya

            hi i would like to know how to sort my dynamic generated table in php when i click on any header row on first click sort acending and on another click sort on decending order. :-D

            R Offline
            R Offline
            Ranjit Viswakumar
            wrote on last edited by
            #5

            There would be 3 components to this process- 1. User-facing page with <div id=data></div> 2. AJAX Javascript 3. Dynamic PHP page The user-facing page will contain an empty div marked by an ID. The AJAX script will be something like- http://whatsaranjit.com/includes/grabData.js[^] Lastly, the PHP page will contain a script like-

            $sql = "SELECT * FROM table";
            if (isset($_GET['q'])) {
            $q = $_GET['q'];
            $sql .= " ORDER BY $q ASC";
            }

            On your user-facing page, you can make your table header a hyperlink-

            <a href='javascript: grabData('headerName', 'data', page.php)'>Sort</a>

            When you click the link, it will refresh the SQL query data into the div named 'data' appending the SQL query to order by whatever variable you pass to the AJAX script. You can expand on this to to get it to ascend/descend. Good luck! Ranjit Viswakumar Professional Services Specialist rviswakumar@hostmysite.com http://hostmysite.com/?utm_source=bb[^]

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups