|
|
|
|
![]() ![]() |
Jul 28 2007, 06:20 PM
Post
#1
|
|
|
Newbie ![]() Group: Members Posts: 5 Joined: 28-July 07 Member No.: 47,157 |
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?
CODE 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>"; } } } |
|
|
|
Jul 28 2007, 06:33 PM
Post
#2
|
|
|
A computer once beat me at chess, but it was no match for me at kick boxing. ![]() Group: [MODERATOR] Posts: 4,076 Joined: 24-July 05 From: Linix, DOS and Windows…the good, the bad and the ugly Member No.: 9,787 ![]() |
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. |
|
|
|
Jul 28 2007, 08:29 PM
Post
#3
|
|
|
Newbie ![]() Group: Members Posts: 5 Joined: 28-July 07 Member No.: 47,157 |
dob field is varchar
current month is whatever type php gives to m |
|
|
|
Jul 28 2007, 09:47 PM
Post
#4
|
|
|
A computer once beat me at chess, but it was no match for me at kick boxing. ![]() Group: [MODERATOR] Posts: 4,076 Joined: 24-July 05 From: Linix, DOS and Windows…the good, the bad and the ugly Member No.: 9,787 ![]() |
From the php Manual:
QUOTE 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. 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? CODE if ($month == $currentmonth && $month != 00 )
Reason for edit: tested some code and reported back
|
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 11th October 2008 - 09:44 PM |