hi friends i make simple database table in php my sql and display data report in html table by each i have a table of 5 to six column like name city area state etc. i want to make each heading link once user click on particular link data is sorted by ascending order by this column, next time user click on same column data is sort by descending order if user click another link data is sort by acending of particular link can anybody tell how to make header link and other verification i want to something like http://demo-admin.magentocommerce.com/index.php/admin/catalog_product/ but now use of javascript or ajax pure php thanks
I personally prefer using tokens to perform the operation you are requesting. The column link might be something like sb = sort by so = sort order (ASC or DESC) 1 = Name 2 = Country <a href='page.php?sb=1'>Name</a> <a href='page.php?sb=2'>Country</a> At the top of the page you would store any tokens in the session <?php session_start(); if($_GET){ if($_SESSION['sb']==$_GET['sb']){ if($_SESSION['so']=='ASC'){ $_SESSION['so']='DESC'; } else { $_SESSION['so']='ASC'; } } else { $_SESSION['sb'] = $_GET['sb']; $_SESSION['so'] = 'ASC'; } } ?> PHP: You can then execute your query with something like mysql_query("SELECT * FROM table ORDER BY '" . $_SESSION['sb'] . "' " . $_SESSION['so']); Theres probably a more efficient way of doing it though.