Page 1 of 1

[solved] having trouble with mysql query?

Posted: Thu Feb 28, 2008 4:42 pm
by zoonose
I am trying to recover a multidimensional array with the following code, however, it doesn't seem to be working!
If i replace $query_date with a numerical (unix timestamp) i.e '1204894800' - it works a treat. i cannot understand why it wont work with a variable?

Code: Select all

$date = mktime(0,0,0,date('m'), date('d'), date('Y'));
$day = date('d', $date);
$month = date('m', $date);
$year = date('Y', $date);
 
$SelMthDays = cal_days_in_month(0, $month, $year);
echo $SelMthDays;
$Palm_events = array();
for ($i=1;$i<=$SelMthDays;$i++){
    $query_date = mktime(0,0,0,$month,$i,$year);
    $sql = "SELECT e_family FROM `dates` WHERE e_date = $query_date";
    $result = mysql_query($sql,$con);
    $Palm_events[$i] = mysql_fetch_row($result);
 
}
 
print_r($Palm_events);

Re: having trouble with mysql query?

Posted: Thu Feb 28, 2008 4:49 pm
by John Cartwright

Code: Select all

$sql = "SELECT e_family FROM `dates` WHERE e_date = $query_date";
echo $sql.'<br>';
$result = mysql_query($sql,$con) or die(mysql_error());
Running this in your script may provide some useful info

Re: having trouble with mysql query?

Posted: Thu Feb 28, 2008 7:13 pm
by Peter Anselmo
Also try outputing the value of $query_date before you run the query to see if it is spitting out a valid timestamp.

Re: having trouble with mysql query?

Posted: Sun Mar 02, 2008 6:22 am
by zoonose
Problem was my zend studio is on my computer and in a different timezone to the server.
script works a treat on the server!!

thanks for your help!