bravo14 Posted June 30, 2008 Share Posted June 30, 2008 Hi all I am trying to display a list of fixtures using if statements. If the Home/Away field is Home I want it to display the fixtures in one way and if it is Away I want it to show another way, I have had a stab at it but am getting an error message on the page at www.yardleyheroes.co.uk/fixtures.php $result = mysql_query('SELECT FROM fixtures ORDER BY date', $con) or die(mysql_error()); if(mysql_num_rows($result) < 1) { echo('<tr class="profiletext"><td colspan="6">Sorry, no results were found.</td></tr>'); } else { while($row = mysql_fetch_array($result)) { if ($row[Home/Away]=="Home") echo ('<tr><td>'.$row[Date].'</td><td><b>Yardley</b></td>'); echo ('<td>'.$row[yardley_goals].'-'.$row[opposition_goals].'</td><td>'.$row[Opposition].'</td>'); echo ('<td></td><td><a href="http://www.yardleyheroes.co.uk/matchfines.php?match_id='.$row[match_id].'"View Fines</a></td></tr>'); else{ echo ('<tr><td>'.$row[Date].'</td><td>'.$row[Opposition]'</td>'); echo ('<td>'.$row[opposition_goals].'-'.$row[yardley_goals].'</td><td>Yardley</td>'); echo ('<td></td><td><a href="http://www.yardleyheroes.co.uk/matchfines.php?').$row[match_id].'<a></td></tr>'); } } mysql_close($con); ?> Cheers Mark Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 30, 2008 Share Posted June 30, 2008 $result = mysql_query('SELECT FROM fixtures ORDER BY date', $con) or die(mysql_error()); if(mysql_num_rows($result) < 1) { echo('<tr class="profiletext"><td colspan="6">Sorry, no results were found.</td></tr>'); } else { while($row = mysql_fetch_array($result)) { if ($row[Home/Away]=="Home") echo ('<tr><td>'.$row[Date].'</td><td><b>Yardley</b></td>'); echo ('<td>'.$row[yardley_goals].'-'.$row[opposition_goals].'</td><td>'.$row[Opposition].'</td>'); echo ('<td></td><td><a href="http://www.yardleyheroes.co.uk/matchfines.php?match_id='.$row[match_id].'"View Fines</a></td></tr>'); } else{ echo ('<tr><td>'.$row[Date].'</td><td>'.$row[Opposition]'</td>'); echo ('<td>'.$row[opposition_goals].'-'.$row[yardley_goals].'</td><td>Yardley</td>'); echo ('<td></td><td><a href="http://www.yardleyheroes.co.uk/matchfines.php?').$row[match_id].'<a></td></tr>'); } } } mysql_close($con); ?> There you go. You missed like 2 braces. Be careful. { } needs to go around everything you want executed in the if/else blocks (or any loop for that matter). Quote Link to comment Share on other sites More sharing options...
bravo14 Posted June 30, 2008 Author Share Posted June 30, 2008 Thank you for your quick response I have copied that text over so it now looks like $result = mysql_query('SELECT FROM fixtures ORDER BY date', $con) or die(mysql_error()); if(mysql_num_rows($result) < 1) { echo('<tr class="profiletext"><td colspan="6">Sorry, no results were found.</td></tr>'); } else { while($row = mysql_fetch_array($result)) { if ($row[Home/Away]=="Home") echo ('<tr><td>'.$row[Date].'</td><td><b>Yardley</b></td>'); echo ('<td>'.$row[yardley_goals].'-'.$row[opposition_goals].'</td><td>'.$row[Opposition].'</td>'); echo ('<td></td><td><a href="http://www.yardleyheroes.co.uk/matchfines.php?match_id='.$row[match_id].'"View Fines</a></td></tr>'); } else{ echo ('<tr><td>'.$row[Date].'</td><td>'.$row[Opposition]'</td>'); echo ('<td>'.$row[opposition_goals].'-'.$row[yardley_goals].'</td><td>Yardley</td>'); echo ('<td></td><td><a href="http://www.yardleyheroes.co.uk/matchfines.php?').$row[match_id].'<a></td></tr>'); } } } mysql_close($con); ?> and get the following error message Parse error: syntax error, unexpected T_ELSE in /home/fhlinux147/y/yardleyheroes.co.uk/user/htdocs/fixtures.php on line 64 Line 64 is else{ Any ideas? Cheers Mark Quote Link to comment Share on other sites More sharing options...
revraz Posted June 30, 2008 Share Posted June 30, 2008 Missing { here if ($row[Home/Away]=="Home") Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 30, 2008 Share Posted June 30, 2008 My bad, I saw it and forgot to correct it. Thanks revraz. Quote Link to comment Share on other sites More sharing options...
bravo14 Posted June 30, 2008 Author Share Posted June 30, 2008 Sorry guys being a bit thick where do I need to put the { at the moment I have done it as follows if {($row[Home/Away]=="Home") and I am getting an error message Sorry about this Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 30, 2008 Share Posted June 30, 2008 Put it on the end of the line... Quote Link to comment Share on other sites More sharing options...
revraz Posted June 30, 2008 Share Posted June 30, 2008 if ($row[Home/Away]=="Home") { All you have to do is look at your other IF statements. And honestly, if you don't know where it goes, you may want to read up more on PHP. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 try this: if ($row['Home/Away']=="Home") { ACE Quote Link to comment Share on other sites More sharing options...
bravo14 Posted July 1, 2008 Author Share Posted July 1, 2008 Thanks for all your help guys, still geting error message Parse error: syntax error, unexpected '[' in /home/fhlinux147/y/yardleyheroes.co.uk/user/htdocs/fixtures.php on line 58 $result = mysql_query('SELECT * FROM `fixtures` ORDER BY `date`', $con) or die(mysql_error()); if(mysql_num_rows($result) < 1) { echo('<tr class="profiletext"><td colspan="7">Sorry, no results were found.</td></tr>'); } else { while($row = mysql_fetch_array($result)) { if ($row.[HomeAway].=="Home") { echo ('<tr><td>'.$row[Date].'</td><td><b>Yardley</b></td>'); echo ('<td>'.$row[yardley_goals].'-'.$row[opposition_goals].'</td><td>'.$row[Opposition].'</td>'); echo ('<td></td><td><a href="http://www.yardleyheroes.co.uk/matchfines.php?match_id='.$row[match_id].'"View Fines</a></td></tr>'); } else{ echo ('<tr><td>'.$row[Date].'</td><td>'.$row[Opposition].'</td>'); echo ('<td>'.$row[opposition_goals].'-'.$row[yardley_goals].'</td><td>Yardley</td>'); echo ('<td></td><td><a href="http://www.yardleyheroes.co.uk/matchfines.php?'.$row[match_id].'<a></td></tr>'); } } } mysql_close($con); ?> Line 58 is if ($row.[HomeAway].=="Home") { Quote Link to comment Share on other sites More sharing options...
bravo14 Posted July 1, 2008 Author Share Posted July 1, 2008 Think I may have solved it, won't know until later. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.