Jump to content


Photo

"Happy Birthday" select..


  • Please log in to reply
5 replies to this topic

#1 Darkness Soul

Darkness Soul
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts
  • LocationBrazil; São Paulo.

Posted 24 April 2006 - 06:56 PM

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:
$sql = "SELECT id, born, name FROM tbMembers WHERE (born > $daysago AND born < $daysafter) ORDER BY born DESC";
$query = mysql_query ( $sql , $conn );
It will test the born year with 2006, so, never select...

Thanks anyway.. =)

D.Soul
(If something is wrong, please tell me. I'm learning this language. Thank you)

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 25 April 2006 - 05:37 PM

Sounds like this 'born' field isn't a DATE, but a CHAR field... this is the first issue. Also, you can use BETWEEN and some date math for N days before/after. Please clarify.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 Darkness Soul

Darkness Soul
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts
  • LocationBrazil; São Paulo.

Posted 26 April 2006 - 06:33 PM

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
(If something is wrong, please tell me. I'm learning this language. Thank you)

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 27 April 2006 - 03:23 AM

I'm sorry, I really don't understand what you're getting at.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 Darkness Soul

Darkness Soul
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts
  • LocationBrazil; São Paulo.

Posted 27 April 2006 - 12:49 PM

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:
$array_date = calc_date ( date ('d/m') , 14 , 7 , 'd/m' ) ;

My array:
array_date:
0 -> 13/4
1 -> 27/4
2 -> 4/5

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:
SELECT id, born, name FROM tbMembers WHERE born >= $array_date[0] AND born <= $array_date[2] ORDER BY born DESC

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

D.Soul
(If something is wrong, please tell me. I'm learning this language. Thank you)

#6 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 27 April 2006 - 04:53 PM

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

SELECT id, born, name FROM tbMembers WHERE born BETWEEN >= NOW() - INTERVAL $days_before DAY AND NOW() + INTERVAL $days_after DAY ORDER BY born DESC

Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users