Jul 25, 2008

Birthday System

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

Birthday System

up2trouble
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>";
}
}
}

 

 

 


Reply

jlhaslip
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.

Reply

up2trouble
dob field is varchar
current month is whatever type php gives to m

Reply

jlhaslip
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 )

 

 

 


Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : birthday


    Looking for birthday, system

Searching Video's for birthday, system
advertisement



Birthday System



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE