0

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>";

	}
2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by diafol
0

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.

Edited by diafol: n/a

0

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?

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.