gw32 Posted August 25, 2011 Share Posted August 25, 2011 Syntax error found: unexpected T_ELSEIF on line 23 <?php require("config.php"); $result = mysql_query("SELECT name, mics, status, date_format(eventStart, '%M %e %Y') as start, date_format(eventFinish, '%M %e %Y') as end FROM events where status='S' or status='A' order BY eventStart"); $sta=$row['status']; { echo "<table rules='rows'> <tr> <th width='50'><font color='yellow' size='1'>MICS</th> <th width='200'><font color='yellow' size='1'>Charity</th> <th width='125'><font color='yellow' size='1'>Start Date</th> <th width='125'><font color='yellow' size='1'>End Date</th> </tr>"; while ($row = mysql_fetch_array($result)) { if ($sta == "A"); { echo "<tr>"; echo "<td><font color='red' size='1'>" . $row['mics'] . "</td>"; echo "<td><font color='red' size='1'>" . $row['name'] . "</td>"; echo "<td><font color='red' size='1'>" . $row['start'] . "</td>"; echo "<td><font color='red' size='1'>" . $row['end'] . "</td>"; echo "</tr>"; } elseif ($sta == "S"); { echo "<tr>"; echo "<td><font color='#ffffff' size='1'>" . $row['mics'] . "</td>"; echo "<td><font color='#ffffff' size='1'>" . $row['name'] . "</td>"; echo "<td><font color='#ffffff' size='1'>" . $row['start'] . "</td>"; echo "<td><font color='#ffffff' size='1'>" . $row['end'] . "</td>"; echo "</tr>"; } } echo "</table>"; } mysql_close($dbh); ?> [code] I don't see it. Thanks Link to comment https://forums.phpfreaks.com/topic/245682-unexpected-t_elseif/ Share on other sites More sharing options...
Pikachu2000 Posted August 25, 2011 Share Posted August 25, 2011 Remove semicolon if ($sta == "A"); // <--- HERE Link to comment https://forums.phpfreaks.com/topic/245682-unexpected-t_elseif/#findComment-1261853 Share on other sites More sharing options...
DarkerAngel Posted August 25, 2011 Share Posted August 25, 2011 there is also a semicolon after the ELSEIF too, there should be no semicolons after your IF statements. Link to comment https://forums.phpfreaks.com/topic/245682-unexpected-t_elseif/#findComment-1261855 Share on other sites More sharing options...
gw32 Posted August 25, 2011 Author Share Posted August 25, 2011 That worked. Now do I have this $sta=$row['status']; in the correct position? Thanks again Link to comment https://forums.phpfreaks.com/topic/245682-unexpected-t_elseif/#findComment-1261857 Share on other sites More sharing options...
gw32 Posted August 25, 2011 Author Share Posted August 25, 2011 Found error about $sta. Thanks guys. Link to comment https://forums.phpfreaks.com/topic/245682-unexpected-t_elseif/#findComment-1261859 Share on other sites More sharing options...
DarkerAngel Posted August 25, 2011 Share Posted August 25, 2011 That worked. Now do I have this $sta=$row['status']; in the correct position? Thanks again I don't see why you have the curly brackets lines 5 and 34 as it's not enclosing any conditions or loops... $sta=$row['status']; { // <- HERE echo "<table rules='rows'> and echo "</table>"; } // <- HERE mysql_close($dbh); Link to comment https://forums.phpfreaks.com/topic/245682-unexpected-t_elseif/#findComment-1261860 Share on other sites More sharing options...
Pikachu2000 Posted August 25, 2011 Share Posted August 25, 2011 As written, $sta will be empty. You're trying to assign it a value before $row['status'] is available. Assuming that 'A' and 'S' are the only possible values for that field, something like this would work for you, with less code. while ($row = mysql_fetch_array($result)) { $color = $row['status'] == 'A' ? 'red' : 'white'; echo "<tr>"; echo "<td><font color='$color' size='1'>" . $row['mics'] . "</td>"; echo "<td><font color='$color' size='1'>" . $row['name'] . "</td>"; echo "<td><font color='$color' size='1'>" . $row['start'] . "</td>"; echo "<td><font color='$color' size='1'>" . $row['end'] . "</td>"; echo "</tr>"; } Link to comment https://forums.phpfreaks.com/topic/245682-unexpected-t_elseif/#findComment-1261861 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.