0

I'm working on a sports website and ran into an issue. There is more than one game on different days and I'm only wanting the date to display once instead of once for every game to be played on that date.

For example: http://seohiosports.com/mastergirlsbasketballschedule2014.php You will see immediately that there are two games listed on November 26. They are displayed like this:

November 26, 2013 Tri-Valley at Crooksville November 26, 2013 Sheridan at John Glenn

I want it to be displayed like this:

November 26, 2013 Tri-Valley at Crooksville Sheridan at John Glenn

Here is the code I'm working with, for some reason or another, I'm struggling to come up with the test/loop I need to make this work how I want it to.

if($num > 0)
{   
    while($row = mysql_fetch_array($r, MYSQLI_ASSOC))
    {           
        echo '<b>'. date("F d, Y",strtotime($row['date'])) .' </b><br/>
              '. $row['awayteam'] . ' '. $row['awayscore'] .' at '. $row['hometeam'] . ' '. $row['homescore'] .' <br/><br/>';
    }

    mysql_free_result($r);
}  

Thanks in advance for any help. I think the answer is probably simple, but I'm struggling for one reason or another.

Thanks!

2 Answers 2

1
<? if ($num > 0)
{   
    $temp_date = '';
    while ($row = mysql_fetch_array($r, MYSQLI_ASSOC))
    {   
        if ($temp_date != $row['date']) {
            $temp_date = $row['date'];
            echo '<b>'. date("F d, Y",strtotime($row['date'])) .' </b><br/>';
        }

           echo $row['awayteam'] . ' '. $row['awayscore'] .' at '. $row['hometeam'] . ' '. $row['homescore'] .' <br/><br/>';
    }

    mysql_free_result($r);
}  
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, this is looking good. Only problem is that I'm getting two <br/> tags in after each game. I would like to only have one after games on the same day. I'm going to see if I can't figure it out. Thanks!
Maybe I could just add a div tag for each row and use CSS to add spacing?
Thanks, I was able to figure it out by adding a <br/> tag before the echo date was executed!
0
<?php
if ($num > 0){
  $dates = Array();
  while ($row = mysql_fetch_array($r, MYSQLI_ASSOC)){ 
    if(!in_array($row['date'], $dates)){
      $dates[] = $row['date'];
      echo $row['date'] . '</br>';
    }

     echo $row['awayteam'] . ' '. $row['awayscore'] .' at '. $row['hometeam'] . ' '. $row['homescore'] .' <br/><br/>';
  }
  mysql_free_result($r);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.