Jump to content

[SOLVED] If... else statement


woolade

Recommended Posts

Can someone please help.  I'm very new at php and just finding my feet, have searched your forum but still can't work out why this doesn't work.

 

I'm trying to use an if...  else statement within fetch_array but keep getting the following error:-

 

Parse error: syntax error, unexpected T_IF in /home/d*****/public_html/php_test.php on line 42

 

Here's my code

 

$query = "SELECT Fixtures.Season, Fixtures.Round, Fixtures.Date, Teams.Name, Fixtures.WinLossDraw, 
Fixtures.OurGrossScore-Fixtures.OurWktsLost*6 AS OurNetScore, Fixtures.OppGrossScore-Fixtures.
OppWktsLost*6 AS OppNetScore FROM Fixtures LEFT JOIN Teams ON Fixtures.vs_Teams_id = Teams.id WHERE Season = 1";

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

echo "<table align=\"center\">
<tr>
<th>Round</th>
<th>Date</th>
<th></th>
<th></th>
<th>Result</th>
<th></th>
<th></th>
<th>W/L/D</th>

</tr>";while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td align=\"center\">" . $row['Round'] . "</td>";
  echo "<td align=\"center\">" . $row['Date'] . "</td>";
  echo "<td align=\"center\">" . "The Pests" . "</td>";
  echo "<td align=\"center\">" . $row['OurNetScore'] . "</td>";
  echo "<td align=\"center\">" . "vs" . "</td>";
  echo "<td align=\"center\">" . if($row['OurNetScore'] > $row['$OppNetScore'])
    		echo "defeated";
    		else
    		echo "defeated by" . "</td>";  echo "<td align=\"center\">" . $row['Name'] . "</td>";
  echo "<td align=\"center\">" . $row['OppNetScore'] . "</td>";
  echo "<td align=\"center\">" . $row['WinLossDraw'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

Link to comment
https://forums.phpfreaks.com/topic/154016-solved-if-else-statement/
Share on other sites

change it to this...

<?php
$query = "SELECT Fixtures.Season, Fixtures.Round, Fixtures.Date, Teams.Name, Fixtures.WinLossDraw, 
Fixtures.OurGrossScore-Fixtures.OurWktsLost*6 AS OurNetScore, Fixtures.OppGrossScore-Fixtures.
OppWktsLost*6 AS OppNetScore FROM Fixtures LEFT JOIN Teams ON Fixtures.vs_Teams_id = Teams.id WHERE Season = 1";

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

echo "<table align=\"center\">
<tr>
<th>Round</th>
<th>Date</th>
<th></th>
<th></th>
<th>Result</th>
<th></th>
<th></th>
<th>W/L/D</th>

</tr>";while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td align=\"center\">" . $row['Round'] . "</td>";
  echo "<td align=\"center\">" . $row['Date'] . "</td>";
  echo "<td align=\"center\">" . "The Pests" . "</td>";
  echo "<td align=\"center\">" . $row['OurNetScore'] . "</td>";
  echo "<td align=\"center\">" . "vs" . "</td>";
  echo "<td align=\"center\">";
  if($row['OurNetScore'] > $row['$OppNetScore']) {
    		echo "defeated";
    		}
    		else {
    		echo "defeated by" . "</td>"; 
	    echo "<td align=\"center\">" . $row['Name'] . "</td>";
	    }
  echo "<td align=\"center\">" . $row['OppNetScore'] . "</td>";
  echo "<td align=\"center\">" . $row['WinLossDraw'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

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.