BLaZuRE Posted July 26, 2009 Share Posted July 26, 2009 How do you include PHP variables inside the text of a MySQL queries. I've been searching but I've found no answers or related questions. If you need an example or you're interested in what I'm trying to do: $query = 'SELECT title FROM myTable WHERE ts_event BETWEEN ' . mktime(0,0,0,$day[m],$day[d],$day[Y]) . ' AND ' . mktime(0,0,0,$nextDay[m],$nextDay[d],$nextDay[Y]); mysql_query($query); Apparently, the query returns nothing. Quote Link to comment https://forums.phpfreaks.com/topic/167442-solved-including-php-inside-mysql-queries/ Share on other sites More sharing options...
BLaZuRE Posted July 26, 2009 Author Share Posted July 26, 2009 I forgot to mention I'm using MySQL version 5.0.77 with PHP 5.2.9 Quote Link to comment https://forums.phpfreaks.com/topic/167442-solved-including-php-inside-mysql-queries/#findComment-882945 Share on other sites More sharing options...
Philip Posted July 26, 2009 Share Posted July 26, 2009 You did it write, but seeing it in color always helps: $query = 'SELECT something FROM table WHERE var = '.$var.' AND another = 1'; Have you tried echo'ing $query to see if it's what you're looking for? Quote Link to comment https://forums.phpfreaks.com/topic/167442-solved-including-php-inside-mysql-queries/#findComment-882983 Share on other sites More sharing options...
smerny Posted July 26, 2009 Share Posted July 26, 2009 nvm Quote Link to comment https://forums.phpfreaks.com/topic/167442-solved-including-php-inside-mysql-queries/#findComment-882988 Share on other sites More sharing options...
BLaZuRE Posted July 26, 2009 Author Share Posted July 26, 2009 You did it write, but seeing it in color always helps: $query = 'SELECT something FROM table WHERE var = '.$var.' AND another = 1'; Have you tried echo'ing $query to see if it's what you're looking for? Yeah, it's echo'ing what I need it to query. I've been trying to see why it's not printing anything for hours at this point. Unless the timestamp appearing in datetime notation has anything to do with it .. but I checked and it's classified as a timestamp. I printed the query itself and it returned a bunch of Resource ID #'s .. should have expected that. (and yes, I've checked the database and the data I'm querying is within the range). Quote Link to comment https://forums.phpfreaks.com/topic/167442-solved-including-php-inside-mysql-queries/#findComment-883034 Share on other sites More sharing options...
BLaZuRE Posted July 26, 2009 Author Share Posted July 26, 2009 For some reason, I read that timestamps store unix time values and interpreted that as they ONLY store as unix time values. Anyway, a simple UNIX_TIMESTAMP() around the column fixed the problem. Thanks for the help. P.S. I can't find the edit or modify button ... so I just keep posting. Quote Link to comment https://forums.phpfreaks.com/topic/167442-solved-including-php-inside-mysql-queries/#findComment-883430 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.