up2trouble 0 Report post Posted July 28, 2007 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
jlhaslip 4 Report post Posted July 28, 2007 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
up2trouble 0 Report post Posted July 28, 2007 dob field is varcharcurrent month is whatever type php gives to m Share this post Link to post Share on other sites
jlhaslip 4 Report post Posted July 28, 2007 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