jeff5656 Posted December 29, 2008 Share Posted December 29, 2008 I want to sort by column name when the user clicks that column. However it does not work (no errors, but the display order is unchanged): displayactive.php: <?php $column_name=$_GET['column_name']; if(isset($column_name) and strlen($column_name)>0){ $query = $query . " order by $column_name "; } $query = "SELECT * FROM `icu` WHERE `signoff_status` = 'a' AND `pod` = '". $pod ."' "; $results = mysql_query ($query) or die (mysql_error()); <table > <th ><a href='displayactive.php?column_name=rm_loc'>Rm</a> </th> <th ><a href='displayactive.php?column_name=patient'> Patient </th> <th > ICU Admit Dx </th> Quote Link to comment https://forums.phpfreaks.com/topic/138757-sort-by-column-name/ Share on other sites More sharing options...
Maq Posted December 29, 2008 Share Posted December 29, 2008 Cause you don't close your PHP tag before table "?>" Quote Link to comment https://forums.phpfreaks.com/topic/138757-sort-by-column-name/#findComment-725491 Share on other sites More sharing options...
gevans Posted December 29, 2008 Share Posted December 29, 2008 swap it all round!!! $column_name=$_GET['column_name']; if(isset($column_name) and strlen($column_name)>0){ $query = $query . " order by $column_name "; } $query = "SELECT * FROM `icu` WHERE `signoff_status` = 'a' AND `pod` = '". $pod ."' "; $results = mysql_query ($query) or die (mysql_error()); should be $query = "SELECT * FROM `icu` WHERE `signoff_status` = 'a' AND `pod` = '". $pod ."'"; if(isset($column_name) and strlen($column_name)>0){ $query = $query . " order by $column_name "; } $results = mysql_query ($query) or die (mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/138757-sort-by-column-name/#findComment-725493 Share on other sites More sharing options...
gevans Posted December 29, 2008 Share Posted December 29, 2008 also there is an error in you sql syntax (which I've fixed) so you would have been having errors if you had them set as on Quote Link to comment https://forums.phpfreaks.com/topic/138757-sort-by-column-name/#findComment-725495 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.