Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-25-2004, 03:46 AM   PM User | #1
dniwebdesign
Regular Coder

 
dniwebdesign's Avatar
 
Join Date: Dec 2003
Location: Carrot River, Saskatchewan
Posts: 838
Thanks: 15
Thanked 9 Times in 9 Posts
dniwebdesign is an unknown quantity at this point
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?
__________________
Dawson Irvine
CEO - DNI Web Design
http://www.dniwebdesign.com
dniwebdesign is offline   Reply With Quote
Old 09-25-2004, 07:16 AM   PM User | #2
raf
Master Coder


 
Join Date: Jul 2002
Posts: 6,589
Thanks: 0
Thanked 0 Times in 0 Posts
raf will become famous soon enoughraf will become famous soon enough
why don't you make the selection inside your query?
__________________
Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html
raf is offline   Reply With Quote
Old 09-25-2004, 06:03 PM   PM User | #3
dniwebdesign
Regular Coder

 
dniwebdesign's Avatar
 
Join Date: Dec 2003
Location: Carrot River, Saskatchewan
Posts: 838
Thanks: 15
Thanked 9 Times in 9 Posts
dniwebdesign is an unknown quantity at this point
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?
__________________
Dawson Irvine
CEO - DNI Web Design
http://www.dniwebdesign.com
dniwebdesign is offline   Reply With Quote
Old 09-25-2004, 06:59 PM   PM User | #4
dniwebdesign
Regular Coder

 
dniwebdesign's Avatar
 
Join Date: Dec 2003
Location: Carrot River, Saskatchewan
Posts: 838
Thanks: 15
Thanked 9 Times in 9 Posts
dniwebdesign is an unknown quantity at this point
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.
__________________
Dawson Irvine
CEO - DNI Web Design
http://www.dniwebdesign.com

Last edited by dniwebdesign; 09-25-2004 at 07:06 PM..
dniwebdesign is offline   Reply With Quote
Old 09-25-2004, 07:14 PM   PM User | #5
litebearer
Regular Coder

 
Join Date: Apr 2004
Posts: 287
Thanks: 0
Thanked 21 Times in 21 Posts
litebearer is on a distinguished road
What format have are you using in the database for your date field (mysql date, int, char) ?
litebearer is offline   Reply With Quote
Old 09-25-2004, 07:18 PM   PM User | #6
dniwebdesign
Regular Coder

 
dniwebdesign's Avatar
 
Join Date: Dec 2003
Location: Carrot River, Saskatchewan
Posts: 838
Thanks: 15
Thanked 9 Times in 9 Posts
dniwebdesign is an unknown quantity at this point
I have the following rows in the forums...

date
month
year
__________________
Dawson Irvine
CEO - DNI Web Design
http://www.dniwebdesign.com
dniwebdesign is offline   Reply With Quote
Old 09-25-2004, 07:36 PM   PM User | #7
litebearer
Regular Coder

 
Join Date: Apr 2004
Posts: 287
Thanks: 0
Thanked 21 Times in 21 Posts
litebearer is on a distinguished road
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...
litebearer is offline   Reply With Quote
Old 09-25-2004, 07:45 PM   PM User | #8
dniwebdesign
Regular Coder

 
dniwebdesign's Avatar
 
Join Date: Dec 2003
Location: Carrot River, Saskatchewan
Posts: 838
Thanks: 15
Thanked 9 Times in 9 Posts
dniwebdesign is an unknown quantity at this point
doesn't seem to work
__________________
Dawson Irvine
CEO - DNI Web Design
http://www.dniwebdesign.com
dniwebdesign is offline   Reply With Quote
Old 09-25-2004, 07:53 PM   PM User | #9
litebearer
Regular Coder

 
Join Date: Apr 2004
Posts: 287
Thanks: 0
Thanked 21 Times in 21 Posts
litebearer is on a distinguished road
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...
litebearer is offline   Reply With Quote
Old 09-25-2004, 08:04 PM   PM User | #10
litebearer
Regular Coder

 
Join Date: Apr 2004
Posts: 287
Thanks: 0
Thanked 21 Times in 21 Posts
litebearer is on a distinguished road
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...
litebearer is offline   Reply With Quote
Old 09-25-2004, 08:06 PM   PM User | #11
litebearer
Regular Coder

 
Join Date: Apr 2004
Posts: 287
Thanks: 0
Thanked 21 Times in 21 Posts
litebearer is on a distinguished road
Is there a specific reason you are choosing not to use either date type fields or timestamps for your date data?
litebearer is offline   Reply With Quote
Old 09-25-2004, 08:35 PM   PM User | #12
marek_mar
Sensei


 
Join Date: Aug 2003
Location: One step ahead of you.
Posts: 2,815
Thanks: 0
Thanked 3 Times in 3 Posts
marek_mar is on a distinguished road
You could store the value returned from time(); in a int(11) field and then get all you want using the date(); function.
marek_mar is offline   Reply With Quote
Old 09-25-2004, 11:14 PM   PM User | #13
dniwebdesign
Regular Coder

 
dniwebdesign's Avatar
 
Join Date: Dec 2003
Location: Carrot River, Saskatchewan
Posts: 838
Thanks: 15
Thanked 9 Times in 9 Posts
dniwebdesign is an unknown quantity at this point
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...
__________________
Dawson Irvine
CEO - DNI Web Design
http://www.dniwebdesign.com
dniwebdesign is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:26 PM.


Advertisement
Log in to turn off these ads.