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. 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'"; 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. 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 . "'"; Link to comment https://forums.phpfreaks.com/topic/262317-help-with-variables/#findComment-1344317 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.