Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Databasing
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 06-28-2009, 04:54 PM
  #1
GameGodUK
Aspirant (Level 2)
 
Join Date: Mar 2009
Posts: 11
iTrader: (0)
GameGodUK is an unknown quantity at this point
MYSQL Query - how to not fetch a record if the date is earlier than today

how can i not fetch gigs that have a date earlier than today,
this is how far ive got
BUT it doesnt work :L
and i cant understand why :@

$date = date("o-m-d");

$gig_query = "SELECT users.*, users_gigs.* FROM users, users_gigs WHERE users.id=users_gigs.mid AND users_gigs.date < $date";

************users_gigs.date isnt a time stamp it is a date field with the date that a user has selected for the gig in the same format ads $date

GameGodUK is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 06-29-2009, 12:05 PM
  #2
GrillMonkey
Warrior (Level 8)
 
Join Date: Jun 2009
Posts: 71
iTrader: (0)
GrillMonkey is an unknown quantity at this point
I could be completely wrong here as I don't use php and mysql (I'm .net and mssql) but I believe you should be using now() instead of $date... ?
GrillMonkey is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 06-29-2009, 02:21 PM
  #3
GameGodUK
Aspirant (Level 2)
 
Join Date: Mar 2009
Posts: 11
iTrader: (0)
GameGodUK is an unknown quantity at this point
Quote:
Originally Posted by GrillMonkey View Post
I could be completely wrong here as I don't use php and mysql (I'm .net and mssql) but I believe you should be using now() instead of $date... ?
the $date is a variable set from my

date("o-m-d");

which gets the date now in format 2009-06-29 < same as is inputted into database,

cheers anyway
GameGodUK is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 06-29-2009, 09:57 PM
  #4
Horus_Kol
Mod of the Underlay
 
Horus_Kol's Avatar
 
Join Date: Jun 2002
Location: At a desk, hooked up and ready to rock
Posts: 17,230
iTrader: (0)
Horus_Kol is a glorious beacon of lightHorus_Kol is a glorious beacon of lightHorus_Kol is a glorious beacon of lightHorus_Kol is a glorious beacon of lightHorus_Kol is a glorious beacon of light
1. is 'date' a DATE type or a DATETIME/TIMESTAMP? this affects the test

DATE fields are just 2009-01-01
DATETIME/TIMESTAMP are 2009-01-01 01:01:01


2. you should use Y and not o to get the year - you will get some odd behaviour around the 1st of January if you use o


3. if you are putting a string into a database ( $date = date("Y-m-d") ) then you need to put quotes around it:

Code:
$gig_query = "SELECT users.*, users_gigs.* FROM users, users_gigs WHERE users.id=users_gigs.mid AND users_gigs.date < '$date' ";
4. finally - I don't think that you can do this comparison straight like that - simpler to use an integer:

PHP Code:

$date 
date("Ymd"); // returns example: 20090630

$gig_query "SELECT users.*, users_gigs.* FROM users, users_gigs WHERE users.id=users_gigs.mid AND users_gigs.date < $date"
that will work if date is a DATE field
if it is DATETIME or TIMESTAMP, then you will have to do this:

PHP Code:
$date date("Ymd") . "000001"// returns 1 second past midnight - first second of today 
__________________
Personal Blog (and photos): HorusKol
Articles on Programming and Development (PHP/HTML/CSS, C/C++, more): RandomTweak

The great secret that no SEO agent wants you to hear: if you build your website using w3c accessibility guidelines and your content is written for people, you will do better for longer in search engines than any other method...
Horus_Kol is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 07-14-2009, 06:04 PM
  #5
Vege
Super Deity (Level 18)
 
Join Date: Sep 2004
Location: Finland
Posts: 3,390
iTrader: (0)
Vege is just really niceVege is just really niceVege is just really niceVege is just really nice
Quote:
SELECT users.*, users_gigs.* FROM users, users_gigs WHERE users.id=users_gigs.mid AND users_gigs.date < date(now())
This should work regardless if the date -column is varchar, date or datetime.

Comments on this post
Horus_Kol agrees: *head-thwok* of course - much simpler
Vege is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote

Reply
KEEP TABS
SPONSORS
 
Boxedart
 
 


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  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
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 04:56 PM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.