chickendude Posted November 17, 2005 Share Posted November 17, 2005 What I'm trying to do is: ==select all the hours for each day up to the inputted date ==(hours are stored in 'day') ==select dates either from before April 30, 2005 or after it (depending on the date inputted) ==add the results together //parameter tossed in: $date //dates are arranged as such: YYYY-MM-DD //initial SELECT statement $stuff = "SELECT day FROM db"; /*if the year > 2005 or month > april and the year = 2005 use the following code:*/ if(substr($date,0,4)>2005 or substr($date,5,2)>4 && substr($date,0,4)==2005) { //just a visual confirmation of the program's path echo 'GREATER '; //concatenate the rest of the statement //this seems to be the part where i need help $stuff = $stuff. " WHERE substr(month,0,4)>2005 OR substr(month,5,2)>4 AND substr(month,0,4)=2005"; } else { //again, confirmation echo 'LESS '; //get the dates before May, 2005 $stuff = $stuff." WHERE substr(month,0,4)<2005 OR substr(month,5,2)<5 AND substr(month,0,4)=2005"; } //see what the final statement being executed is echo $stuff."\n"; //run the statement $tothours = 0; $result = mysql_query($stuff, $login_db) or ezine_mysql_die(); while($num = mysql_fetch_object($result)) { //get the total number of hours $tothours += ($num->day); //this statement displays nothing, no results are returned. echo $db."::"; } //it displays 0 echo $tothours; And for the record, there are entries in the database that meet the criteria for both sides. If you can find the/some errors in my code, I'd definitely appreciate it. Thanks alot. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.