Jump to content

Getting my table to display results correctly


Simplicity

Recommended Posts

Hi there

I'm sure this is one of those glaringly obvious mistakes that I just can't see for looking.

Could someone take a quick look at the code below and suggest what I've done wrong.  I've already screamed at my husband 3 times for no good reason on account of this and you'd really be doing him a favour.  ;)

[code]<?php

require_once ('mysql_connect.php');

$sql = 'SELECT `RTeamName` , SUM( `RGamePld` ) , SUM( `RGameWon` ) , SUM( `RGameLost` ) , SUM( `RGameDraw` ) , SUM( `DLegFor` ) , SUM( `DLegAgainst` ) , SUM( `RPointsSum` ) '
        . ' FROM `LeagueTable` '
        . ' WHERE `RDivision` = \'A\''
        . ' GROUP BY `RTeamName` '
        . ' ORDER BY `RPointsSum` DESC LIMIT 0, 30';

echo '<table width="555" border="1" cellspacing="0" cellpadding="2">
      <tr>
        <td width="60">Team Name</td>
        <td width="20"><div align="center">Played</div></td>
        <td width="20"><div align="center">Won</div></td>
        <td width="20"><div align="center">Lost</div></td>
        <td width="20"><div align="center">Drawn</div></td>
        <td width="20"><div align="center">Legs For</div></td>
        <td width="20"><div align="center">Legs Against</div></td>
        <td width="20"><div align="center">Points</div></td>
      </tr>';
 
$result= mysql_query($sql)OR die (mysql_error());


if ($result) {
while ($row=mysql_fetch_array($result)){
echo '<tr><td> '. $row['RTeamName'] .' </td><td>'. $row['RGamePld'] .'</td><td>'.$row[' RGameWon'] .'</td><td>'.$row[' RGameLost'] .'</td><td>'.$row[' RGameDraw'] .'</td><td>'.$row[' RGameDraw'] .'</td><td>'.$row[' DLegFor'] .'</td><td>'.$row[' DLegAgainst'] .'</td><td>'.$row['  RPointsSum'] .'</td><tr>';}
}else{
echo '<p>The current query did not execute successfully  ' .mysql_error() . '<br /><br /> Query: '. $query .' </p>';}
echo '</table>';
mysql_close();

?>[/code]

I'm trying to get the table headers to display with the query results in the column underneath the headers.  My SQL query is sound and works fine using PHPMyAdmin to query the database... just having problems getting the PHP right for the page to display it.  Can anyone make any suggestions.

What I do get displayed on the page is:
[quote]Team Name Pld Won Lost Drawn Legs For Legs Against Points Team Name Pld Won Lost Drawn Legs For Legs Against Points $result= mysql_query($sql)OR die (mysql_error()); if ($result) { while ($row=mysql_fetch_array($result)){ '. $row['RTeamName'] .' '. $row['RGamePld'] .''.$row[' RGameWon'] .''.$row[' RGameLost'] .''.$row[' RGameDraw'] .''.$row[' RGameDraw'] .''.$row[' DLegFor'] .''.$row[' DLegAgainst'] .''.$row[' RPointsSum'] .'';} }else{ echo '

The current query did not execute successfully ' .mysql_error() . '

Query: '. $query .'
';} mysql_close(); ?>[/quote]

any assistance you can provide would be appreciated.

S x
Hi.

In the $result query, change [color=red]OR[/color] to [color=blue]or[/color].

Try this version of code.

[code]
<?php

require_once ('mysql_connect.php');

$sql = "SELECT RTeamName , SUM(RGamePld ) , SUM( RGameWon ) , SUM(RGameLost) , SUM(RGameDraw) , SUM(DLegFor) , SUM(DLegAgainst) , SUM(RPointsSum) FROM LeagueTable WHERE RDivision=A GROUP BY RTeamName ORDER BY RPointsSum DESC LIMIT 0, 30";

echo "<table width='555' border='1' cellspacing='0' cellpadding='2'>
      <tr>
        <td width='60'>Team Name</td>
        <td width='20'><div align='center'>Played</div></td>
        <td width='20'><div align='center'>Won</div></td>
        <td width='20'><div align='center'>Lost</div></td>
        <td width='20'><div align='center'>Drawn</div></td>
        <td width='20'><div align='center'>Legs For</div></td>
        <td width='20'><div align='center'>Legs Against</div></td>
        <td width='20'><div align='center'>Points</div></td>
      </tr>";

$result = mysql_query($sql) or die(mysql_error());


if ($result) {
while ($row=mysql_fetch_array($result)){
echo "<tr><td> ". $row['RTeamName'] ." </td><td>". $row['RGamePld'] ."</td><td>".$row[' RGameWon'] ."</td><td>".$row[' RGameLost'] ."</td><td>".$row[' RGameDraw'] ."</td><td>".$row[' RGameDraw'] ."</td><td>".$row[' DLegFor'] ."</td><td>".$row[' DLegAgainst'] ."</td><td>".$row['  RPointsSum'] ."</td></tr>";}
}else{
echo "<p>The current query did not execute successfully  " .mysql_error() . "<br /><br /> Query: ". $query ." </p>";}
echo "</table>";
mysql_close();

?>
[/code]
Here is the solution:

[code]
<?php

require_once ('mysql_connect.php');

$sql = "SELECT RTeamName , SUM(RGamePld ) , SUM( RGameWon ) , SUM(RGameLost) , SUM(RGameDraw) , SUM(DLegFor) , SUM(DLegAgainst) , SUM(RPointsSum) FROM LeagueTable WHERE RDivision=A GROUP BY RTeamName ORDER BY RPointsSum DESC LIMIT 0, 30";

echo "<table width='555' border='1' cellspacing='0' cellpadding='2'>
      <tr>
        <td width='60'>Team Name</td>
        <td width='20'><div align='center'>Played</div></td>
        <td width='20'><div align='center'>Won</div></td>
        <td width='20'><div align='center'>Lost</div></td>
        <td width='20'><div align='center'>Drawn</div></td>
        <td width='20'><div align='center'>Legs For</div></td>
        <td width='20'><div align='center'>Legs Against</div></td>
        <td width='20'><div align='center'>Points</div></td>
      </tr>";

$result = mysql_query($sql) or die(mysql_error());


if ($result) {
while ($row=mysql_fetch_array($result)){
echo "<tr><td> ". $row['RTeamName'] ." </td><td>". $row['SUM(RGamePld)'] ."</td><td>".$row['SUM(RGameWon)'] ."</td><td>".$row['SUM(RGameLost)'] ."</td><td>".$row[' SUM(RGameDraw)'] ."</td><td>".$row['SUM(RGameDraw)'] ."</td><td>".$row['SUM(DLegFor)'] ."</td><td>".$row['SUM(DLegAgainst)'] ."</td><td>".$row['SUM(RPointsSum)'] ."</td></tr>";}
}else{
echo "<p>The current query did not execute successfully  " .mysql_error() . "<br /><br /> Query: ". $query ." </p>";}
echo "</table>";
mysql_close();

?>
[/code]
You have one same row.

[code]
<?php

require_once ('mysql_connect.php');

$sql = "SELECT RTeamName , SUM(RGamePld ) , SUM(RGameWon ) , SUM(RGameLost) , SUM(RGameDraw) , SUM(DLegFor) , SUM(DLegAgainst) , SUM(RPointsSum) FROM LeagueTable WHERE RDivision=A GROUP BY RTeamName ORDER BY RPointsSum DESC LIMIT 0, 30";

echo "<table width='555' border='1' cellspacing='0' cellpadding='2'>
      <tr>
        <td width='60'>Team Name</td>
        <td width='20'><div align='center'>Played</div></td>
        <td width='20'><div align='center'>Won</div></td>
        <td width='20'><div align='center'>Lost</div></td>
        <td width='20'><div align='center'>Drawn</div></td>
        <td width='20'><div align='center'>Legs For</div></td>
        <td width='20'><div align='center'>Legs Against</div></td>
        <td width='20'><div align='center'>Points</div></td>
      </tr>";

$result = mysql_query($sql) or die(mysql_error());


if ($result) {
while ($row=mysql_fetch_array($result)){
echo "<tr><td> ". $row['RTeamName'] ." </td><td>". $row['SUM(RGamePld)'] ."</td><td>".$row['SUM(RGameWon)'] ."</td><td>".$row['SUM(RGameLost)'] ."</td><td>".$row[' SUM(RGameDraw)'] ."</td><td>".$row['SUM(DLegFor)'] ."</td><td>".$row['SUM(DLegAgainst)'] ."</td><td>".$row['SUM(RPointsSum)'] ."</td></tr>";}
}else{
echo "<p>The current query did not execute successfully  " .mysql_error() . "<br /><br /> Query: ". $query ." </p>";}
echo "</table>";
mysql_close();
?>
[/code]

How about now?

Thank you for attaching a picture.  :)
It helped me.  :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.