Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.