gamerzfuse Posted May 12, 2009 Share Posted May 12, 2009 The old forum post solved my problem entirely, but it just introduced another one. Rather than having a 3 page post with a new problem, I decided to start over here. Situation: I have the code: $sSql = $vehicles->SelectSQL(); I edited that function to include: // Table level SQL function SqlSelect() { // Select return "SELECT * FROM `vehicles`"; } function SqlWhere() { // Where Type return "type= '". mysql_real_escape_string($_GET['type']) . "'"; //Used to say just return ""; } function SqlGroupBy() { // Group By return ""; } function SqlHaving() { // Having return ""; } function SqlOrderBy() { // Order By return ""; } Now I have a working sort on all of my pages that have a specified type (in example: http://www.example.com/inventory.php?type=car ) The problem is that if I have no type, then it lists no vehicles. How can I use an if/then statement or the empty() to make it not display a type if there is no type listed? Thanks again everyone! Link to comment https://forums.phpfreaks.com/topic/157815-solved-organize-by-type-only-if-type-specified/ Share on other sites More sharing options...
GingerRobot Posted May 12, 2009 Share Posted May 12, 2009 Quote How can I use an if/then statement or the empty() to make it not display a type if there is no type listed? Pretty much as you describe there. The logic is: if the variable is not empty, search using the variable. If it's not, dont add a where clause. Link to comment https://forums.phpfreaks.com/topic/157815-solved-organize-by-type-only-if-type-specified/#findComment-832391 Share on other sites More sharing options...
gamerzfuse Posted May 12, 2009 Author Share Posted May 12, 2009 Quote Quote How can I use an if/then statement or the empty() to make it not display a type if there is no type listed? Pretty much as you describe there. The logic is: if the variable is not empty, search using the variable. If it's not, dont add a where clause. The closest I can come is: function SqlWhere() { // Where Type return (!empty($_GET['type'])) ? "type = '". mysql_real_escape_string($_GET['type']) . "' : ""; } Link to comment https://forums.phpfreaks.com/topic/157815-solved-organize-by-type-only-if-type-specified/#findComment-832394 Share on other sites More sharing options...
Ken2k7 Posted May 12, 2009 Share Posted May 12, 2009 Fix your quotes. Link to comment https://forums.phpfreaks.com/topic/157815-solved-organize-by-type-only-if-type-specified/#findComment-832407 Share on other sites More sharing options...
gamerzfuse Posted May 12, 2009 Author Share Posted May 12, 2009 Quote Fix your quotes. That's what I'm trying to do. I can't seem to get it right. I take out one of the ending quotes and all my colors are fine again, but then I get an error about unexpected ; Link to comment https://forums.phpfreaks.com/topic/157815-solved-organize-by-type-only-if-type-specified/#findComment-832424 Share on other sites More sharing options...
mikr Posted May 12, 2009 Share Posted May 12, 2009 What gamerzfuse means, is, below... function SqlWhere() { // Where Type return (!empty($_GET['type'])) ? "type = '". mysql_real_escape_string($_GET['type']) . "'" : ""; //return (!empty($_GET['type'])) ? "type = '". mysql_real_escape_string($_GET['type']) . "' : ""; } Look closely, you weren't closing out your final single quote after the mysql_real_escape_string(). I've left yours in as commented out so you can see what you missed. Hope that helps. Link to comment https://forums.phpfreaks.com/topic/157815-solved-organize-by-type-only-if-type-specified/#findComment-832434 Share on other sites More sharing options...
gamerzfuse Posted May 12, 2009 Author Share Posted May 12, 2009 Quote What gamerzfuse means, is, below... function SqlWhere() { // Where Type return (!empty($_GET['type'])) ? "type = '". mysql_real_escape_string($_GET['type']) . "'" : ""; //return (!empty($_GET['type'])) ? "type = '". mysql_real_escape_string($_GET['type']) . "' : ""; } Look closely, you weren't closing out your final single quote after the mysql_real_escape_string(). I've left yours in as commented out so you can see what you missed. Hope that helps. I used that and now I get an unexpected T_Var? Thanks though, if you could just advise me on this one last thing.. I'll be done with this site almost. Noob mistake. Left in an extra } Works great. Hopefully this fixes all my problems! Thanks for the tolerance Ken Link to comment https://forums.phpfreaks.com/topic/157815-solved-organize-by-type-only-if-type-specified/#findComment-832439 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.