This topic is locked

Birthdate into a Birthday Groups List table

10/1/2007 6:27:07 PM
PHPRunner General questions
D
dorlisa author

Good Day Everyone,
Can you help me figure out this riddle. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=6387&image=1&table=forumtopics' class='bbc_emoticon' alt=':blink:' />
I have two tables:
_members

_birthday_groups
When members sign up they are asked for their birthday. Once that birthdate

is captured in the _members table, I would like it to be automatically added to

the '_birthday_groups' table under their birthday group.
Their name should be added to their birthday group like shown below:
Here are the Birthday Groups in the '_birthday_groups' table:


I figured it is an Insert a record into another table event, but I am stuck after that.
Thanks for your help!
phpnewbie

J
Jane 10/2/2007

Hi,
here is a sample code:

global $conn;

$bgroup = date("n",$values["BirthDate"]);
if ($bgroup==1 or $bgroup==2)

$bgroup_name = "Jan - Feb";

if ($bgroup==3 or $bgroup==4)

$bgroup_name = "Mar - Apr";

// ...
if ($bgroup && $bgroup_name)

{

$strInsert = "insert into _birthday_groups (bgroup_name,bgroup_members) values ('".$bgroup_name."','".$values["Firstname"].", ".$values["LastName"]."')";

db_exec($strInsert,$conn);

}

D
dorlisa author 10/2/2007

Thanks Jane for the Sample Code:
I changed some of the code a little to the following. I had a few questions about this code, see my picture below:
global $conn;
$bgroup = date("n",$values["bday"]);
if ($bgroup==1 or $bgroup==2)

$bgroup_name = "Jan - Feb";

if ($bgroup==3 or $bgroup==4)

$bgroup_name = "Mar - Apr";

if ($bgroup==5 or $bgroup==6)

$bgroup_name = "May - Jun";

if ($bgroup==7 or $bgroup==8)

$bgroup_name = "Jul - Aug";

if ($bgroup==9 or $bgroup==10)

$bgroup_name = "Sep - Oct";

if ($bgroup==11 or $bgroup==12)

$bgroup_name = "Nov - Dec";

//

if ($bgroup && $bgroup_name)

{

$strInsert = "insert into _bday_groups (bgroup_name,bg_members)

values ('".$bgroup_name."','".$values["first_name"].", ".$values["last_name"].",: ".$values["bday"]."')";

db_exec($strInsert,$conn);

}


Then I got this error:

J
Jane 10/4/2007

Hi,
if you use AfterSuccessfulRegistration event you need to use $userdata array instead of $values.

Here is the correct code:

global $conn;

$bgroup = date("n",$userdata["bday"]);
if ($bgroup==1 or $bgroup==2)

$bgroup_name = "Jan - Feb";

if ($bgroup==3 or $bgroup==4)

$bgroup_name = "Mar - Apr";

if ($bgroup==5 or $bgroup==6)

$bgroup_name = "May - Jun";

if ($bgroup==7 or $bgroup==8)

$bgroup_name = "Jul - Aug";

if ($bgroup==9 or $bgroup==10)

$bgroup_name = "Sep - Oct";

if ($bgroup==11 or $bgroup==12)

$bgroup_name = "Nov - Dec";

//

if ($bgroup && $bgroup_name)

{

$strInsert = "insert into _bday_groups (bgroup_name,bg_members)

values ('".$bgroup_name."','".$userdata["first_name"].", ".$userdata["last_name"].",: ".$userdata["bday"]."')";

db_exec($strInsert,$conn);

}



where bday, first_name and last_name are your actual field names.

D
dorlisa author 10/6/2007

Hi Jane,
That worked! Thanks...but
Whenever I add a new member...no matter what birthday

month they actually fall under it keeps putting

in Nov - Dec as the bgroup_name.
For example:

If their birthday is 02/11/1968, it adds it in the _bday_groups table as:
First Name Last Name: 1968-02-11 Nov - Dec
When it should be:
First Name Last Name: 1968-02-11 Jan - Feb
By the way...

Is there a way to change the format of that date to.... February 2, 1968
Thanks.

J
Jane 10/6/2007

Hi,
sorry for my fault.

Here is the correct code:

global $conn;

$bgroup = date("n",strtotime($userdata["bday"]));

...


To format date use date function:

http://php.net/manual/en/function.date.php