thomasw_lrd Posted May 9, 2012 Share Posted May 9, 2012 I've got a select statement that looks like this in php. $sql = "Select * from inventory where ".$fields."".$operator."".$criteria; Everything posts correctly, everything is dereferenced correctly. My only question is how do I get $criteria have single quotes around it? So that when I actually run the query it says select * from inventory where field = 'value'; I've tried $sql = "Select * from inventory where ".$fields."".$operator.""'.$criteria'; $sql = "Select * from inventory where ".$fields."".$operator.""'$criteria'; and a bunch of variations like that. Thanks for you help. Quote Link to comment https://forums.phpfreaks.com/topic/262317-help-with-variables/ Share on other sites More sharing options...
Maq Posted May 9, 2012 Share Posted May 9, 2012 Look up interpolation: $sql = "Select * from inventory where $fields $operator '$criteria'"; Quote Link to comment https://forums.phpfreaks.com/topic/262317-help-with-variables/#findComment-1344297 Share on other sites More sharing options...
thomasw_lrd Posted May 9, 2012 Author Share Posted May 9, 2012 Thanks I knew it was a stupid error on my part. I had actually tried "select * from ". $fields $operator '$criteria'; But that didn't work, and I didn't think of trying any other variations of that. Quote Link to comment https://forums.phpfreaks.com/topic/262317-help-with-variables/#findComment-1344304 Share on other sites More sharing options...
Maq Posted May 9, 2012 Share Posted May 9, 2012 You can do it that way but you have to concatenate everything: $sql = "select * from " . $fields . " " . $operator . " '" . $criteria . "'"; Quote Link to comment https://forums.phpfreaks.com/topic/262317-help-with-variables/#findComment-1344317 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.