|
Posted by Rik on 07/17/07 15:44
On Tue, 17 Jul 2007 17:25:31 +0200, up2trouble <lynettesmith@gmail.com> =
=
wrote:
> I'm trying to search my db and display everyone who has a birthday
> that month. I fixed the forever loop and it displaying people without=
> a birthdate entered. The problem is it keeps changing the currentmonth=
> variable.
>
> function displayBirthdays($connect, $db_table4)
> {
> $currentmonth =3D date("m");
> $currentday =3D date("d");
>
> $sql =3D "SELECT dob, lastName, firstName FROM $db_table4";
> $result =3D mysql_query ($sql, $connect) or die ('Query failed:
> ' .mysql_error());
> while ($row =3D mysql_fetch_array($result))
> {
> $lastname =3D $row["lastName"];
> $firstname =3D "***";
> $dob =3D $row['dob'];
> $month =3D substr($dob,0,2);
> $day =3D substr($dob,3,2);
> if ($currentmonth =3D $month AND $month !=3D 00)
> {
> echo "$month";
> echo "$currentmonth";
> echo"$firstname $lastname [$day]<BR>";
> }
> }
> }
>
> 0606*** Whitfield [22]
> 0303*** Scanlan [09]
> 1111*** Whitfield [29]
> 0303*** Shive [15]
> 0808*** Keckeisen [22]
> 0505*** sookram [06]
>
Don't check the month in PHP, databases are optimised for this kind of =
thing.
$sql =3D "SELECT dob, lastName, firstName FROM $db_table4 WHERE MONTH(do=
b) =3D =
MONTH(CURDATE())";
-- =
Rik Wasmus
Navigation:
[Reply to this message]
|