amg182 Posted July 2, 2011 Share Posted July 2, 2011 Hi guys, I have a variable assigned for car model type and would like it to be part of my query WHERE clause. So I figured it should look like this, but doesnt seem to work... $Model='lexus'; ...... $sql = "SELECT COUNT(*) FROM (Select * FROM cars WHERE Make='$Model') subq"; Am i missing something here? It works fine if I manually type in "lexus" but doesnt like the variable? Any ideas? Link to comment https://forums.phpfreaks.com/topic/240958-variable-where-cluase/ Share on other sites More sharing options...
Pikachu2000 Posted July 2, 2011 Share Posted July 2, 2011 What is the "subq" at the end supposed to be doing? Link to comment https://forums.phpfreaks.com/topic/240958-variable-where-cluase/#findComment-1237670 Share on other sites More sharing options...
PFMaBiSmAd Posted July 2, 2011 Share Posted July 2, 2011 Have you echoed $sql so that you know if it actually contains what you think? I suspect, based on the lack of actual code, that where you are setting $Model at and where you are using it are not in the same scope. Link to comment https://forums.phpfreaks.com/topic/240958-variable-where-cluase/#findComment-1237672 Share on other sites More sharing options...
amg182 Posted July 2, 2011 Author Share Posted July 2, 2011 Yeah, it was out of range/scope. I juggled it around based on what you said and is working fine now! Thanks guys much appreciated. Link to comment https://forums.phpfreaks.com/topic/240958-variable-where-cluase/#findComment-1237676 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.