Simplicity Posted November 18, 2006 Share Posted November 18, 2006 Hi thereI'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 Link to comment https://forums.phpfreaks.com/topic/27690-getting-my-table-to-display-results-correctly/ Share on other sites More sharing options...
Adika Posted November 18, 2006 Share Posted November 18, 2006 Hi.In the $result query, change [color=red]OR[/color] to [color=blue]or[/color].Try this version of code.[code]<?phprequire_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] Link to comment https://forums.phpfreaks.com/topic/27690-getting-my-table-to-display-results-correctly/#findComment-126643 Share on other sites More sharing options...
Simplicity Posted November 18, 2006 Author Share Posted November 18, 2006 Excellent. Thanks!At least now my table is sort of displaying. Now the RTeamName is correctly populating the first column but the other table items are not populating. Any suggestions? Link to comment https://forums.phpfreaks.com/topic/27690-getting-my-table-to-display-results-correctly/#findComment-126650 Share on other sites More sharing options...
Adika Posted November 18, 2006 Share Posted November 18, 2006 Here is the solution:[code]<?phprequire_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] Link to comment https://forums.phpfreaks.com/topic/27690-getting-my-table-to-display-results-correctly/#findComment-126655 Share on other sites More sharing options...
Simplicity Posted November 18, 2006 Author Share Posted November 18, 2006 Thanks AdikaCopied your code but its displaying like this?! Screen dump attached[attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/27690-getting-my-table-to-display-results-correctly/#findComment-126665 Share on other sites More sharing options...
Adika Posted November 18, 2006 Share Posted November 18, 2006 You have one same row.[code]<?phprequire_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. :) Link to comment https://forums.phpfreaks.com/topic/27690-getting-my-table-to-display-results-correctly/#findComment-126672 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.