[solved] having trouble with mysql query?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zoonose
Forum Newbie
Posts: 8
Joined: Wed Aug 29, 2007 7:44 am

[solved] having trouble with mysql query?

Post 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);
Last edited by zoonose on Sun Mar 02, 2008 6:23 am, edited 2 times in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: having trouble with mysql query?

Post 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
User avatar
Peter Anselmo
Forum Commoner
Posts: 58
Joined: Wed Feb 27, 2008 7:22 pm

Re: having trouble with mysql query?

Post 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.
zoonose
Forum Newbie
Posts: 8
Joined: Wed Aug 29, 2007 7:44 am

Re: having trouble with mysql query?

Post 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!
Post Reply