0

I have a mysql query that returns 5 rows via PHP myadmin but when I attempt to load it via a php page - I'm getting nothing back.

Here is the select statement:

$result = mysqli_query($con,"select ID, MatchWon, MatchLost, MatchTied, (( MatchWon + (.5 * MatchTied ))/( MatchWon + MatchLost + MatchTied )) as WinPCT
FROM
(
SELECT ID, 
SUM ( CASE WHEN MatchResult = 'Won' THEN 1 ELSE 0 END ) MatchWon, 
SUM ( CASE WHEN MatchResult = 'Lost' THEN 1 ELSE 0 END ) MatchLost,
SUM ( CASE WHEN MatchResult = 'Tied' THEN 1 ELSE 0 END ) MatchTied
FROM 
(
    SELECT hometeam AS ID, 
    CASE WHEN homescore > visitorscore THEN 'Won'
    WHEN homescore < visitorscore THEN 'Lost'
    WHEN homescore = visitorscore THEN 'Tied'
    END AS MatchResult
    FROM scores

    UNION ALL   
    SELECT visitingteam AS ID, 
    CASE WHEN homescore < visitorscore THEN 'Won'
    WHEN homescore > visitorscore THEN 'Lost'
    WHEN homescore = visitorscore THEN 'Tied'
    END AS MatchResult
    FROM scores
) as wonlosttable
GROUP BY ID ) as countwinlosstable
ORDER BY WinPCT desc, MatchWon desc, MatchLost asc, MatchTied asc
");

Here is the php code I'm using to display:

while($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td align=center>" . $row['ID'] . "</td>";
  echo "<td align=center>" . $row['MatchWon'] . "</td>";
  echo "<td align=center>" . $row['MatchLost'] . "</td>";
  echo "<td align=center>" . $row['MatchTied'] . "</td>";
  echo "</tr>";
  }

Here is the simple table creation code if needed for testing:

CREATE TABLE `scores` (
  `gameid` int(11) NOT NULL auto_increment,
  `datesubmitted` varchar(50) NOT NULL,
  `gamedate` varchar(11) NOT NULL,
  `gametime` time NOT NULL,
  `visitingteam` varchar(50) NOT NULL,
  `visitorscore` int(11) NOT NULL,
  `hometeam` varchar(50) NOT NULL,
  `homescore` int(11) NOT NULL,
  `submitter` varchar(50) NOT NULL,
  PRIMARY KEY  (`gameid`)
) ENGINE=MyISAM AUTO_INCREMENT=27 DEFAULT CHARSET=latin1 AUTO_INCREMENT=27 ;

-- 
-- Dumping data for table `scores`
-- 

INSERT INTO `scores` VALUES (23, '7/30/2013 9:33:01 AM', '7/24/2013', '17:00:00', 'Culvers', 8, 'Siebe Studios', 2, 'MAXWELL');
INSERT INTO `scores` VALUES (26, '7/30/2013 9:58:37 AM', '7/24/2013', '18:00:00', 'Jimmy Johns', 10, 'Home Technology Systems', 3, 'MAXWELL');
INSERT INTO `scores` VALUES (25, '7/30/2013 9:47:52 AM', '7/29/2013', '15:00:00', 'Jimmy Johns', 10, 'Home Technology Systems', 3, 'MAXWELL');
INSERT INTO `scores` VALUES (24, '7/30/2013 9:46:34 AM', '7/26/2013', '10:30:00', 'Ellis', 5, 'Happy Joes', 13, 'MAXWELL');
homermac
  • 111
  • 1
  • 1
  • 9
  • 2
    Define *I'm getting nothing back.* Blank page? Any errors? – Jason McCreary Jul 30 '13 at 21:04
  • 1
    Check [How do i enable error reporting](http://stackoverflow.com/questions/6575482/php-how-do-i-enable-error-reporting) and check back here after trying it out. Did your format the mysql query the exact same way in your file? – Tobias Golbs Jul 30 '13 at 21:05
  • `printf("Error: %s\n", mysqli_error($con));` = ? – Prix Jul 30 '13 at 21:20

1 Answers1

1

your SUM they have spaces.

change this

     SUM ( CASE WHEN MatchResult = 'Won' THEN 1 ELSE 0 END ) MatchWon, 
     SUM ( CASE WHEN MatchResult = 'Lost' THEN 1 ELSE 0 END ) MatchLost,
     SUM ( CASE WHEN MatchResult = 'Tied' THEN 1 ELSE 0 END ) MatchTied
        ^^-----//--spaces here

to

     SUM( CASE WHEN MatchResult = 'Won' THEN 1 ELSE 0 END ) MatchWon, 
     SUM( CASE WHEN MatchResult = 'Lost' THEN 1 ELSE 0 END ) MatchLost,
     SUM( CASE WHEN MatchResult = 'Tied' THEN 1 ELSE 0 END ) MatchTied
echo_Me
  • 37,078
  • 5
  • 58
  • 78