WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-11-2008, 10:16 AM
amkma amkma is offline
WebProWorld New Member
 

Join Date: Oct 2004
Location: London
Posts: 6
amkma RepRank 0
Default mysql php - help needed

I have a Mysql table with 4 fields.
id, name, date_of_birth and email.
I want to display some record from Mysql, where date_of_birth is todays date, But I don't want to display those records whose email field is null or empty.

I don't know how to do this.
Reply With Quote
  #2 (permalink)  
Old 03-11-2008, 04:42 PM
activeco activeco is offline
WebProWorld Veteran
 

Join Date: Jul 2004
Posts: 859
activeco RepRank 1
Default Re: mysql php - help needed

SELECT * from MyTable where date_of_birth = CURDATE() and where EXISTS (SELECT email FROM mytable);

should work.
Also you could try ...and where email <>"";

or something in that line.
__________________
Vote Hussein, vote humanity

Last edited by activeco : 03-11-2008 at 04:49 PM.
Reply With Quote
  #3 (permalink)  
Old 03-11-2008, 05:18 PM
DaveSawers's Avatar
DaveSawers DaveSawers is offline
WebProWorld Veteran
 

Join Date: Dec 2006
Location: Calgary, Alberta, Canada
Posts: 332
DaveSawers RepRank 1
Default Re: mysql php - help needed

Presumably you want to identify a birthday and thus you will only want the part of the date of birth that excludes the year part and compare it against the current date without the current year added.

If so, then activeco's SQL won't help you.

For a more specific answer, let us know the format of the date_of_birth field in your MySQL database.
__________________
Dynamic Software Development
www.activeminds.ca
Reply With Quote
  #4 (permalink)  
Old 03-11-2008, 05:32 PM
activeco activeco is offline
WebProWorld Veteran
 

Join Date: Jul 2004
Posts: 859
activeco RepRank 1
Default Re: mysql php - help needed

You are right Dave. Amkma probably needs month and date only in which case something like (RIGHT(CURDATE(),5)=RIGHT(date_of_birth,5)) could be used, under condition that date is in yyyy-mm-dd format.
__________________
Vote Hussein, vote humanity
Reply With Quote
  #5 (permalink)  
Old 03-12-2008, 09:13 AM
wige's Avatar
wige wige is offline
Moderator
WebProWorld Moderator
 

Join Date: Jun 2006
Location: United States
Posts: 1,647
wige RepRank 4wige RepRank 4wige RepRank 4
Default Re: mysql php - help needed

This should work, I believe:

SELECT * FROM table WHERE MONTH(date_of_birth) = MONTH(CURDATE()) AND DAY(date_of_birth) = DAY(CURDATE()) AND email NOT NULL AND email !='';

Edit for less processing overhead:

SELECT * FROM table WHERE DATEFORMAT(date_of_birth, '%c %e') = DATEFORMAT(CURDATE(), '%c %e') AND email NOT NULL AND email !='';

You could go even easier, if there is a large database, and replace the second DATEFORMAT() with a PHP variable containing the current date and month, separated by a space.
__________________
The best way to learn anything, is to question everything.
Interestingly Average Security Blog

Last edited by wige : 03-12-2008 at 09:18 AM.
Reply With Quote
  #6 (permalink)  
Old 03-17-2008, 10:19 AM
amkma amkma is offline
WebProWorld New Member
 

Join Date: Oct 2004
Location: London
Posts: 6
amkma RepRank 0
Default Re: mysql php - help needed

Many thanks to all of you.

The following solution helped me out:

$curdate=date("YmdHis");

SELECT * FROM table WHERE date_of_birth = $curdate AND email !=''


Cheers.
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP / MySQL / AJAX Expert Needed weslinda Services for Sale/Hire 0 10-20-2006 04:57 PM
Help needed in php mysql freegk Database Discussion Forum 2 09-16-2005 06:59 PM
very basic php/mysql help needed. wen_laat Database Discussion Forum 6 11-20-2004 08:40 PM
mySQL Query Needed WildSeeker Database Discussion Forum 0 01-30-2004 03:52 PM
MySql on windows xp? -NO HELP NEEDED simone Database Discussion Forum 6 01-19-2004 02:19 AM


Search Engine Friendly URLs by vBSEO 3.0.0