Jump to content

"Happy Birthday" select..


Darkness Soul

Recommended Posts

Hi guys,

I like to ask about a date select.. how my topic name tell, I want to select the daily births..

The user open the page and, in a div, have all the members who are at birthday..

But, my logic problem is: The table record the born, like... 20/10/1987, 09/06/1981.. and my select test if born is between afternoon and tomorrow.. this test is because i want to select between 3 days ago and 3 days after..

Actualy:
[code]$sql = "SELECT id, born, name FROM tbMembers WHERE (born > $daysago AND born < $daysafter) ORDER BY born DESC";
$query = mysql_query ( $sql , $conn );[/code]
It will test the born year with 2006, so, never select...

Thanks anyway.. =)

D.Soul
Link to comment
https://forums.phpfreaks.com/topic/8284-happy-birthday-select/
Share on other sites

Yo,

Born is a TIMESTAMP field, like 20060426152712 (YmdHmi).

My function return an array with three dates.. array( before , now , after );

What I do? I call that function and as parameter, before is how many days ago, after is how many days after..

What I want from the select? Check a date, like NOW().. into select, want to test a time begins $before and going to $after.. so, show me all results between these two fields..

^^" sorry for "complex" english.. trying hard to learn faster \o\~~..

Thanks, D.Soul
Link to comment
https://forums.phpfreaks.com/topic/8284-happy-birthday-select/#findComment-31039
Share on other sites

Let me try one more time, if you don't understood, I will ask for help to 'rewrite' my question.. ;)

You open my site... in the index, you have a list with who are at birthday.. to make that list, my script do:

1. call the date function, that will calc the 'begin' and the 'end' of the date select;
2. call the select, that will filter this date and order by date..
3. print the list

my function is like:
fuction calc_date ( $today , $days_before , $days_after , $date_format )

so, i call it:
[b]$array_date = calc_date ( date ('d/m') , 14 , 7 , 'd/m' ) ;[/b]

My array:
[b]array_date:
0 -> 13/4
1 -> 27/4
2 -> 4/5[/b]
0 is $today - $days_before,
1 is $today,
2 is $today + $days_after.

My SELECT is suppose to get all data between $array_date[0] and $array_date[2].. if the date match.. it will be listed.. so, in the site main, that will list all the guys in birth.. like:
[b]SELECT id, born, name FROM tbMembers WHERE born >= $array_date[0] AND born <= $array_date[2] ORDER BY born DESC[/b]

better now? ^^" sorry for the mess..

D.Soul
Link to comment
https://forums.phpfreaks.com/topic/8284-happy-birthday-select/#findComment-31304
Share on other sites

You could also do the following and not both the either the array or the PHP date functions at all:

[code]SELECT id, born, name FROM tbMembers WHERE born BETWEEN >= NOW() - INTERVAL $days_before DAY AND NOW() + INTERVAL $days_after DAY ORDER BY born DESC[/code]
Link to comment
https://forums.phpfreaks.com/topic/8284-happy-birthday-select/#findComment-31372
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.