Date and get the next event

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Wooster
Forum Newbie
Posts: 2
Joined: Thu Jul 29, 2004 3:33 pm

Date and get the next event

Post by Wooster »

feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


I would like to be able to show the next sporting event. Even if it is 30 days out, or 2 days away.

I have a lot of dated schedules on the site, yet I cant get things to work for the next event. I tried doing Limit 1, but I am sure it does not work due to my date code.

Here is part of the code that needs fixed

Code: Select all

<?php
      include '../connect.php';
      $today=getdate();
      //Start from Sunday
      if($today  > 0){
      $start=mktime (0,0,0,date("m")  ,date("d"),date("Y"));
      }//Create first week
$x = -1;
echo(' <TR height="40" align="center" valign="top"><FONT color="#FFFF00" SIZE="1" FACE="Verdana, Helvetica, Arial">');
while ($x < 50){
if($x==1){
echo('</font></tr>');
}
      $check=date("Y-m-d",mktime (0,0,0,date("m",$start)  ,date("d",$start)+$x,date("Y",$start)));	
      $day = date("D M d",mktime (0,0,0,date("m",$start)  ,date("d",$start)+$x,date("Y",$start)));
      $result = @mysql_query("SELECT ddate ,dheader,dtime,copp,nhome,ncon,iidgender,iidgame,nwooscore,noppscore  FROM fbschedule WHERE iidgender=$iidgender and iidtype=$iidtype AND ddate='$check' LIMIT 1");
      if (!$result) {
      die('<p>Error retrieving data: ' . mysql_error() .    '</p>');
      }								
      if (mysql_num_rows($result) > 0) {
      $time = mysql_result($result,0,'dtime');
	  $date = mysql_result($result,0,'ddate');
      $copp = mysql_result($result,0,'copp');								
      $home=mysql_result($result,0,'nhome');
      $con=mysql_result($result,0,'ncon');
      $woo=mysql_result($result,0,'nwooscore');
      $opp=mysql_result($result,0,'noppscore');
      $game = mysql_result($result,0,'iidgame');
      $dhead = mysql_result($result,0,'dheader');
      $res='';				
      $at='';
      $b='';
      $bb='';										
      $c='';
      $bg='';
      $dh='';										
      $link='<a href="'.$go.''.$chref.'/games/game_stats.php?iidgame='.$game.'&iidgender='.$game['iidgender'].'&iidtype='.$game['iidtype'].'">';
      if($woo > $opp)
      {$time='';
      $wl='<b>Won</b>&nbsp;<br>';
      $res=$woo.' - '.$opp.'<br>';
      }else{
      if($woo == $opp){
      $time=$time.'&nbsp;';
      $wl='';
      }else{
      $wl='Lost<br>';
      $res=$woo.' - '.$opp.'<br>';
      $time='';}
      if($home ==1){
      $at = ' at ';}
      else{
      $bg = '#CCCCCC';
      $b = '<b>';
      $bb= '</b>';}
      if($dhead ==1){
      $dh = ' DH <br>';}
      else{
      $dh = '';}
      if($con==1){
      $c='*';}}		
      echo('<td width="500" valign="top"><font color="#000000" size="2" face="Verdana, Helvetica, Arial">'."$day&nbsp;$dh$at<em>$b$copp$c$bb</em>&nbsp;$time</div></font></td><tr>");
      }
      $x++;
      }			
      ?>
which produces the following because I have it set for 50 days out.

Up next for the Generals:

Fri Aug 27 PERRY 7:30
Fri Sep 03 at MOUNT VERNON 7:30
Fri Sep 10 LAKE 7:30

I would like it to just produce 1 event, no matter the amount of days I ask it to look in.

Any help I would be thankful. I am sure I will kick it around some more tonight.


feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

If you store the date of the event as a unix epoch time then you can just order by the date where date is after the current time:

Code: Select all

"SELECT * FROM blah WHERE date > ".time()." ORDER BY date LIMIT 1";
Wooster
Forum Newbie
Posts: 2
Joined: Thu Jul 29, 2004 3:33 pm

Post by Wooster »

That may just work. I have added it, and it shows the next event, though it is on 2004-08-27.

Thanks, will let you know in a month

Kevin
Post Reply