Jump to content

Sort by column name


jeff5656

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/138757-sort-by-column-name/
Share on other sites

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());

Link to comment
https://forums.phpfreaks.com/topic/138757-sort-by-column-name/#findComment-725493
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.