Jump to content

[SOLVED] Including PHP inside MySQL queries


BLaZuRE

Recommended Posts

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.

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).

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.