jeff5656 Posted January 21, 2009 Share Posted January 21, 2009 I want to sort by column which works, however I want to make the default sort colum "rm_loc" However, when I add the else statement, I get You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 $query = "SELECT * FROM `icu` WHERE `signoff_status` = 'a' AND `pod` = '". $pod ."' "; $column_name=$_GET['column_name']; if(isset($column_name) and strlen($column_name)>0){ $query = $query . " order by $column_name "; } else { $query = $query . " order by $rm_loc "; } Link to comment https://forums.phpfreaks.com/topic/141775-syntax-error-after-adding-else-statement/ Share on other sites More sharing options...
revraz Posted January 21, 2009 Share Posted January 21, 2009 echo $column_name and $rm_loc to make sure they contain something. Link to comment https://forums.phpfreaks.com/topic/141775-syntax-error-after-adding-else-statement/#findComment-742184 Share on other sites More sharing options...
lonewolf217 Posted January 21, 2009 Share Posted January 21, 2009 I dont think those backticks are necessary (`) in your SQL statement, try taking them out Link to comment https://forums.phpfreaks.com/topic/141775-syntax-error-after-adding-else-statement/#findComment-742188 Share on other sites More sharing options...
revraz Posted January 21, 2009 Share Posted January 21, 2009 Backticks are always a good idea. Link to comment https://forums.phpfreaks.com/topic/141775-syntax-error-after-adding-else-statement/#findComment-742190 Share on other sites More sharing options...
jeff5656 Posted January 21, 2009 Author Share Posted January 21, 2009 1. They do contain something. But if they didn't would it give me a syntax error>? 2. The ticks are not the problem. Like I said, the syntax error came about AFTER I added the last three lines of the else statement. Everything above works. Link to comment https://forums.phpfreaks.com/topic/141775-syntax-error-after-adding-else-statement/#findComment-742206 Share on other sites More sharing options...
revraz Posted January 21, 2009 Share Posted January 21, 2009 Echo $query and post it. The error is telling you the problem, near '' which is a empty value. Link to comment https://forums.phpfreaks.com/topic/141775-syntax-error-after-adding-else-statement/#findComment-742209 Share on other sites More sharing options...
jeff5656 Posted January 21, 2009 Author Share Posted January 21, 2009 Never mind I figured it out. it should be rm_loc not $rm_loc (since it is a field name) Link to comment https://forums.phpfreaks.com/topic/141775-syntax-error-after-adding-else-statement/#findComment-742213 Share on other sites More sharing options...
revraz Posted January 21, 2009 Share Posted January 21, 2009 So it didn't contain anything Link to comment https://forums.phpfreaks.com/topic/141775-syntax-error-after-adding-else-statement/#findComment-742215 Share on other sites More sharing options...
jeff5656 Posted January 21, 2009 Author Share Posted January 21, 2009 :-) Link to comment https://forums.phpfreaks.com/topic/141775-syntax-error-after-adding-else-statement/#findComment-742223 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.