Jump to content

Substr help


chickendude

Recommended Posts

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.