Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Birthday System
up2trouble
post 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>";
}
}
}
Go to the top of the page
 
+Quote Post
jlhaslip
post 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 Icon

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
Spam Patrol



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.
Go to the top of the page
 
+Quote Post
up2trouble
post 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
Go to the top of the page
 
+Quote Post
jlhaslip
post 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 Icon

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
Spam Patrol



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
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Spam Is 30 Years Old May 3, 2008(14)
  2. Credit System V2.0 Online(27)
  3. 64 Bit Operating System(2)
  4. Happy 10th Birthday To Google(9)
  5. How To Remember Complex Passwords(11)
  6. Simple Php Login And Registration System(15)
  7. Innovative Login System(20)
  8. What Operating System Do You Use?(15)
  9. The System Doesn't Let Me Apply For Hosting Upgrade [resolved](4)
  10. Is It Actually Worth Joining The Army System(13)
  11. Blood Grouping System(3)
  12. Its's Official Microsoft Is Done With The Windows Operating System(13)
  13. Suggestions For Version 3 Of The Credit System(28)
  14. Level Up System?(1)
  15. Simple Javascript And Password System(9)
  1. Creating A Shortcut List Near The System Tray(4)
  2. What's Your Favorite Game System - Console(181)
  3. Content Management System (cms)(13)
  4. Microsoft Vs. Macintosh(34)
  5. Creating A Php Login System Using Mysql(10)
  6. Install Two Anti-virus Software In 1 System(37)
  7. Adventure11 - Internet Surfing Game And Advertising System(4)
  8. Virtual Pc 7 For Mac(11)
  9. What's Your First System?(93)
  10. System Does Not Detect Dvd/cdrom Drive(21)
  11. Game Maker(15)
  12. School's Blocking System.(28)
  13. 5.1 Sound System Problems(8)
  14. Browse System Files In The Browser...(2)
  15. Get 30 Gb Email For Free(31)


 



- Lo-Fi Version Time is now: 11th October 2008 - 09:44 PM