Jump to content


Photo

Substr help


  • Please log in to reply
No replies to this topic

#1 chickendude

chickendude
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 17 November 2005 - 03:53 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users