-3

I've tried using the codes from this site: https://www.ibm.com/developerworks/library/x-buildpdfphp/ to test. However, there are syntax errors found on a php page. Here's the code: I've placed the 'Syntax Error' to where the errors were located.

<html><head><title>Event Results</title></head>
<body>
<?php
include_once ('XML.php');
$results = getResults();
foreach( $results as $event ) {
?>
<h1><?php echo( $event['name']) ?></h1>
<table><tbody>
<?php
foreach( $event['games'] as $game ) {
  $s1 = (int) $game['score1'];  <-- Syntax Error Here -->
  $s2 = (int) $game['score2'];  <-- Syntax Error Here -->
?>
<tr>
  <td style="font-weight:<?php echo( ( $s1 > $s2 ) ? 'bold' : 'normal') ?>">
    <?php echo( $game['team1'] ) ?></td>
  <td><?php echo( $s1 ) ?></td>
  <td style="font-weight:<?php echo( ( $s2 > $s1 ) ? 'bold' : 'normal') ?>">
    <?php echo( $game['team2'] ) ?></td>
  <td><?php echo( $s2 ) ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
}
?>
</body></html>
NH Narumi
  • 9
  • 10

1 Answers1

1

Solution: Remove the second foreach.

Note: Remove the comment of the first lines and remove the mockup.

<html><head><title>Event Results</title></head>
<body>
<?php
//include_once ('XML.php');
//$results = getResults();

// mockup
$results = array(
                    0=>array(
                                    "name"=>"Basket",
                                    "games"=>array(
                                                    "score1"=>"70",
                                                    "score2"=>"90",
                                                    "team1"=>"Los Supremos",
                                                    "team2"=>"Rapid Fox"
                                                    )
                                   ),    
                    1=>array(
                                    "name"=>"Baseball",
                                    "games"=>array(
                                                    "score1"=>"20",
                                                    "score2"=>"6",
                                                    "team1"=>"Girls Bats",
                                                    "team2"=>"Powergirls"
                                                    )
                                   ),                                       
                );

//var_dump($results);
//die();


foreach( $results as $event ) 
{
    ?>
    <h1><?php echo( $event['name']) ?></h1>
    <table><tbody>
    <?php
    $game = $event['games'];

      $s1 = $game['score1'];  //<-- Syntax Error Here -->
      $s2 = $game['score2'];  //<-- Syntax Error Here -->
    ?>
    <tr>
      <td style="font-weight:<?php echo( ( $s1 > $s2 ) ? 'bold' : 'normal') ?>">
        <?php echo( $game['team1'] ) ?></td>
      <td><?php echo( $s1 ) ?></td>
      <td style="font-weight:<?php echo( ( $s2 > $s1 ) ? 'bold' : 'normal') ?>">
        <?php echo( $game['team2'] ) ?></td>
      <td><?php echo( $s2 ) ?></td>
    </tr>
    </tbody>
    </table>    
    <?php
}
?>

</body></html>
  • Thanks for the solution. So basically by using this method I won't have to use the xml (code that was included). – NH Narumi Dec 06 '16 at 07:15