calculations with php

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

buzzby247
Forum Newbie
Posts: 23
Joined: Wed Jan 14, 2009 6:19 am

Re: calculations with php

Post by buzzby247 »

i have managed to get differring results using the date1 and date2 parameters that i needed using this code:

Code: Select all

$usabilityQuery1 = "SELECT avg(usability) as avgUsability1 FROM usabilityresults WHERE dateSubmitted between DATE_SUB(now(), interval 1 DAY) and now()";
$usabilityresult1=mysql_query($usabilityQuery1);  
$usabilityRow1 = mysql_fetch_array($usabilityresult1);
 
$usabilityQuery2 = "SELECT avg(usability) as avgUsability2 FROM usabilityresults WHERE dateSubmitted between DATE_SUB(now(), interval 2 DAY) and now()";
$usabilityresult2=mysql_query($usabilityQuery2);  
$usabilityRow2 = mysql_fetch_array($usabilityresult2);
what i would like to know is if i can have named (specific) dates. this would mean that i can have the results for any given month or months
buzzby247
Forum Newbie
Posts: 23
Joined: Wed Jan 14, 2009 6:19 am

Re: calculations with php

Post by buzzby247 »

i have been looking at this page: http://dev.mysql.com/doc/refman/5.1/en/ ... n_datediff but i still am not able to find a solution to my predicament which is to return results between 2 given dates rather than using the INTERVAL parameter. is there a way of doing this?
buzzby247
Forum Newbie
Posts: 23
Joined: Wed Jan 14, 2009 6:19 am

Re: calculations with php

Post by buzzby247 »

ok, i have managed to figure out what was needed to get my results between 2 exact dates. and infact its less coding than using the interval prameter

Code: Select all

"SELECT avg(storednumber) as avgStoredNumber FROM tbl_results WHERE dateSubmitted BETWEEN '2009-01-16 10:00:55' AND '2009-01-19 09:37:02'"
that's what works.
Post Reply