jeff5656 Posted April 16, 2009 Share Posted April 16, 2009 I want to sort columns by clicking the name of each column (see code) but I get this error: Notice: Undefined index: column_name in C:\wamp\www\mc\displaybundle.php on line 24 $query = "SELECT * FROM icu WHERE signoff_status = 'a' "; $column_name=$_GET['column_name']; /*<--- this is line 24*/ if(isset($column_name) and strlen($column_name)>0){ $query = $query . " order by $column_name "; } else { $query = $query . " order by rm_loc "; } $results = mysql_query ($query) or die (mysql_error()); $num_pts = mysql_num_rows ($results); and here are the column headings starting down at line 41 <th width="5%" align="left"><a href='displaybundle.php?column_name=rm_loc'> Room</a></th> <th width="5%" align="center"><a href='displaybundle.php?column_name=pod'>Pod</a></th> This error GOES AWAY after I sort a column for the first time! Link to comment https://forums.phpfreaks.com/topic/154421-undefined-index/ Share on other sites More sharing options...
soak Posted April 16, 2009 Share Posted April 16, 2009 Move your isset up a couple of lines: <?php $column_name=(isset($_GET['column_name']) ? $_GET['column_name'] : ''); /*<--- this is line 24*/ if(strlen($column_name)>0){ $query = $query . " order by $column_name "; } Link to comment https://forums.phpfreaks.com/topic/154421-undefined-index/#findComment-811937 Share on other sites More sharing options...
Kalland Posted April 16, 2009 Share Posted April 16, 2009 Hi, Try this: <?php if(isset($_GET['column_name'])) { $column_name = $_GET['column_name']; } else { $column_name = 'order by rm_loc'; } Link to comment https://forums.phpfreaks.com/topic/154421-undefined-index/#findComment-811938 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.