woolade Posted April 14, 2009 Share Posted April 14, 2009 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 More sharing options...
MasterACE14 Posted April 14, 2009 Share Posted April 14, 2009 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>"; Link to comment https://forums.phpfreaks.com/topic/154016-solved-if-else-statement/#findComment-809590 Share on other sites More sharing options...
woolade Posted April 14, 2009 Author Share Posted April 14, 2009 Thanks MasterACE14, u r a legend. Link to comment https://forums.phpfreaks.com/topic/154016-solved-if-else-statement/#findComment-809595 Share on other sites More sharing options...
MasterACE14 Posted April 14, 2009 Share Posted April 14, 2009 thank you Link to comment https://forums.phpfreaks.com/topic/154016-solved-if-else-statement/#findComment-809596 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.