Enjoy an ad free experience by logging in. Not a member yet?
Register .
09-25-2004, 03:46 AM
PM User |
#1
Regular Coder
Join Date: Dec 2003
Location: Carrot River, Saskatchewan
Posts: 838
Thanks: 15
Thanked 9 Times in 9 Posts
Date Problems?
I am having troubles with the below:
PHP Code:
$year = date ( "Y" );
$month = date ( "n" );
$date = date ( "j" );
$count = $count + 1 ;
$date1 = $row [ "date" ];
$year1 = $row [ "year" ];
$month1 = $row [ "month" ];
if( $month1 == "1" )
{ $month2 = "January" ; }
else if( $month1 == "2" )
{ $month2 = "February" ; }
else if( $month1 == "3" )
{ $month2 = "March" ; }
else if( $month1 == "4" )
{ $month2 = "April" ; }
else if( $month1 == "5" )
{ $month2 = "May" ; }
else if( $month1 == "6" )
{ $month2 = "June" ; }
else if( $month1 == "7" )
{ $month2 = "July" ; }
else if( $month1 == "8" )
{ $month2 = "August" ; }
else if( $month1 == "9" )
{ $month2 = "September" ; }
else if( $month1 == "10" )
{ $month2 = "October" ; }
else if( $month1 == "11" )
{ $month2 = "November" ; }
else if( $month1 == "12" )
{ $month2 = "December" ; }
if( $count <= $front_cols && $count == 1 ){echo "" ;}
else if( $count < $front_cols && $count > 1 ){echo "" ;}
else if( $count == $front_cols ){echo "" ;}
if( $month1 >= $month && $year1 >= $year && $date1 >= $date )
{
echo "<tr><td><font size='$font_size' face='$font_face'>" . $month2 . " " . $date1 . ", " . $year1 . "</font></td>
<td><font size='$font_size' face='$font_face'>" . $row [ "venu" ]. "</font></td>
<td><font size='$font_size' face='$font_face'>" . $row [ "location" ]. "</font></td>
<td><font size='$font_size' face='$font_face'>" . $row [ "time" ]. "</font></td>
<td><font size='$font_size' face='$font_face'>$" . $row [ "tickets" ]. "</font></td>
</tr>" ;
}
else
{
echo "" ;
}
I only want it to show the things that are coming up into the future and today, not ones that have happened already. However it just doesn't seem to be working. Any help?
09-25-2004, 07:16 AM
PM User |
#2
Master Coder
Join Date: Jul 2002
Posts: 6,589
Thanks: 0
Thanked 0 Times in 0 Posts
why don't you make the selection inside your query?
09-25-2004, 06:03 PM
PM User |
#3
Regular Coder
Join Date: Dec 2003
Location: Carrot River, Saskatchewan
Posts: 838
Thanks: 15
Thanked 9 Times in 9 Posts
So I can do it by
PHP Code:
$query = mysql_query ( "SELECT * FROM the_database WHERE $month1>='$month' AND $year1>='$year' AND $date1>='$date'" );
However if so, why did the last code bring up every listing there was anyway?
09-25-2004, 06:59 PM
PM User |
#4
Regular Coder
Join Date: Dec 2003
Location: Carrot River, Saskatchewan
Posts: 838
Thanks: 15
Thanked 9 Times in 9 Posts
Well I seem to have got it working so it doesn't show past dates... kind of. It works however I am having trouble not showing past dates in the same month.
if I use the query:
PHP Code:
$query = mysql_query ( "SELECT * FROM the_database WHERE $month1>='$month' AND $year1>='$year' AND $date1>='$date'" );
It will show me the dates from today and beyond... for example, show me dates on 2004 and next years coming... good. However with the date it will not show me the info on October 23 if todays date is 25, but we are still in September.... I think I explained this right, but ask if it needs clearing up because I would really liked this solved and I am totally lost.
Last edited by dniwebdesign; 09-25-2004 at 07:06 PM ..
09-25-2004, 07:14 PM
PM User |
#5
Regular Coder
Join Date: Apr 2004
Posts: 287
Thanks: 0
Thanked 21 Times in 21 Posts
What format have are you using in the database for your date field (mysql date, int, char) ?
09-25-2004, 07:18 PM
PM User |
#6
Regular Coder
Join Date: Dec 2003
Location: Carrot River, Saskatchewan
Posts: 838
Thanks: 15
Thanked 9 Times in 9 Posts
I have the following rows in the forums...
date
month
year
09-25-2004, 07:36 PM
PM User |
#7
Regular Coder
Join Date: Apr 2004
Posts: 287
Thanks: 0
Thanked 21 Times in 21 Posts
I presume you have your date data saved as numbers rather than text (ie 9 rather than September). If so, this may help...
(not 100% certain can concatenate in a query)
PHP Code:
<?PHP
$this_date = date ( "Y" ) . date ( "m" ) . date ( "d" ); // produces 20040925
$this_date = $this_date * 1 ; // my silly way of making sure its an int and not a string
$sql = "SELECT * FROM the_database WHERE ((year . month . date) >= '$this_date')" ;
?>
Lite...
09-25-2004, 07:45 PM
PM User |
#8
Regular Coder
Join Date: Dec 2003
Location: Carrot River, Saskatchewan
Posts: 838
Thanks: 15
Thanked 9 Times in 9 Posts
doesn't seem to work
09-25-2004, 07:53 PM
PM User |
#9
Regular Coder
Join Date: Apr 2004
Posts: 287
Thanks: 0
Thanked 21 Times in 21 Posts
hmmmm
the problem may be that your month and date fields do not contain leading zeros, while the number you are comparing them against does use the leading zeros.
I need to ponder a solution.
Lite...
09-25-2004, 08:04 PM
PM User |
#10
Regular Coder
Join Date: Apr 2004
Posts: 287
Thanks: 0
Thanked 21 Times in 21 Posts
Try this...
PHP Code:
$this_year = date ( "Y" );
$this_month = date ( "m" );
$this_date = date ( "d" );
$this_year = $this_year * 1 ;
$this_month = $this_month * 1 ;
$this_date = $this_date * 1 ;
$sql = "SELECT * FROM the_database WHERE ((year >= '$this_year') AND (month >= '$this_month') AND (date >= '$this_date'))" ;
Lite...
09-25-2004, 08:06 PM
PM User |
#11
Regular Coder
Join Date: Apr 2004
Posts: 287
Thanks: 0
Thanked 21 Times in 21 Posts
Is there a specific reason you are choosing not to use either date type fields or timestamps for your date data?
09-25-2004, 08:35 PM
PM User |
#12
Sensei
Join Date: Aug 2003
Location: One step ahead of you.
Posts: 2,815
Thanks: 0
Thanked 3 Times in 3 Posts
You could store the value returned from
time(); in a int(11) field and then get all you want using the
date(); function.
09-25-2004, 11:14 PM
PM User |
#13
Regular Coder
Join Date: Dec 2003
Location: Carrot River, Saskatchewan
Posts: 838
Thanks: 15
Thanked 9 Times in 9 Posts
Quote:
Originally Posted by litebearer
hmmmm
the problem may be that your month and date fields do not contain leading zeros, while the number you are comparing them against does use the leading zeros.
I need to ponder a solution.
Lite...
No, the number I am using do not have leading zeros, nor do the numbers I'm comparing them to...
as far as the other things... i don't know how they work yet...
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 04:26 PM .
Advertisement
Log in to turn off these ads.