Jump to content

unexpected T_ELSEIF


gw32

Recommended Posts

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

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

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

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.