I have a query:
$startdate= date('Y-m-d H:i:s',strtotime("-1 week"));
$query = "SELECT title FROM new_books ".
"WHERE timestamp >= '$startdate' ";
$newbooks = mysql_query($query) or die (mysql_error());
Is the value of $startdate evaluated when $query is set, or when it’s called by mysql_query()?
For example say the above query returns 0 results (mysql_num_rows($newbook)==0) could I change $startdate and then call $newbooks = mysql_query... again, or would I need to set $query again first?
The variable is evaluated at the time $query is set.
It’s exactly like doing this:
If you want to execute the same query multiple times with different parameters, use prepared statements:
See the examples at http://docs.php.net/manual/en/mysqli.prepare.php