Jump to content
xisto Community
up2trouble

Birthday System

Recommended Posts

When there are no birthdays for a particular month, I would like for it to say "There are no birthdays this month". When I tried, I got the phrase returned for every record in the db. Any suggestions?

function displayBirthdays($connect, $db_table4){$sql = "SELECT dob, lastName, firstName FROM $db_table4 ORDER BY dob";$result = mysql_query ($sql, $connect) or die ('Query failed: ' .mysql_error()); while ($row = mysql_fetch_array($result)){$lastname = $row["lastName"];$firstname = $row["firstName"];$dob = $row['dob'];$month = substr($dob,0,2);$day = substr($dob,3,2);$currentmonth = date("m");if ($month == $currentmonth && $month != 00 ){echo"<FONT SIZE='+1'>$firstname $lastname - [$day]</FONT><BR>";}}}

Share this post


Link to post
Share on other sites

One thing to check for in the If statement is the data type of the Month and Currentmonth.If one is numeric and the other is text, your comparison might fail for that reason. Not sure, but worth checking out.

Share this post


Link to post
Share on other sites

From the php Manual:

Returns a formatted date string.

so, if the date is stored as a numeric value, I think you are comparing apples to oranges and the comparison is failing for that reason.

 

search:php type casting to see if you can compare apples to apples.

 

*edit*

 

Nope. that isn't it. the following code forces a type casting onto the data and the comparison still works, so it must be something else in the code.

 

<?php$lastname = Haslip;$firstname = Jim;$month = (integer) "12"; // except grab it from the database$currentmonth = (string) 12;if ($month == $currentmonth  ){echo "$firstname $lastname has a birthday today<br />";} else {echo "no match comparing $firstname $lastname 's birthday month <br />";}?>
to continue debugging this problem, insert some echo statements in the output to display both the month from the dob field and the current month as per the date () to compare the results manually.

 

Also, check this line and tell me if the negative assignment for the $month being compared to '00' is correct?

 

if ($month == $currentmonth && $month != 00 )

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.