If someone could help, that would be great....

Ok i want the data to be displayed together.... eg. 'week 1' displayed once then all the matches in a single table below, then prints 'week 2' follwed by the matches in the following table rather than continually stating 'week 1' and a new table for every match?

Any ideas?

$query  = "SELECT week, home, away FROM fixtures ORDER BY week ASC";

$results = mysql_query($query);
while(list($week, $home, $away)= mysql_fetch_row($results))
{
  echo " <br> <strong> $week </strong>"  
    ."<table> <tr> <th> Home Team </th> <th> </th> <th> Away Team </th> </tr> <td>$home </td>" . " <td><strong>vs</strong></td> <td>$away</td></tr></table> <br>";

	}
Member Avatar for diafol

You should use the [ CODE ] tag to place code in your post not post as a code snippet. These snippets are usually used for tutorials or solutions for others to use.

OK,

$wk = 0; $output="";
$head = "<table><thead><tr><th>Home Team</th><th>$nbsp;</th><th>Away Team</th></tr></thead><tbody>";
$end = "</tbody></table>";
while($data = mysql_fetch_array($results)){
  if($data['week'] != $wk){
     if($output != "")$output.= $end;
     $output .= "<h3>Week {$data['week']}</h3>" . $head;
     $wk = $data['week'];
  }
  $output .= "<tr>{$data['home']}<td></td><td>vs.</td><td>{$data['away']}</td></tr>";
}
$output .= $end;

//then echo out $output wherever it's required in your html

Not tested - off the top of my head. But I imagine you need something like that.

Thanks for your help, when i echo the output, it only displays the lists of teams in a paragraph rather than a table? Do you know why?

Member Avatar for diafol

Well, I can assure you it won't be a paragraph! No <p> elements. A <td> element was missing. This may work:

$output .= "<tr><td>{$data['home']}</td><td>vs.</td><td>{$data['away']}</td></tr>";

Sorry, I didn't test it. Still haven't, but I hope it's close enough for you to fiddle with it if it doesn't work.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.