Ok, I have looked over and over this code but I can’t seem to find the problem and why I am getting this error, here is the end of the file:
function ouputMainSlider() {
global $USER;
// Get details
$query = "SELECT id, bigimage, heading, fullarticle, dateadded FROM news WHERE status = 1 ";
$query .= "AND (state = '" . $USER->state . "' OR state = 'ALL') AND newstype != 1 and bigimage != '' ";
$query .= "ORDER BY dateadded DESC LIMIT 10";
$restresult = mysql_query($query);
while ($restaurant = mysql_fetch_array($restresult)) :
// Trim article for preview
$preview = trim_str($restaurant['fullarticle'], 270);
?>
<li>
<img alt="<?=fixup($restaurant['heading'])?>" src="images/frontpage/<?=$restaurant['bigimage']?>" width="615" height="309" />
<a href="#" class="read-more">Read More</a>
<p>
<strong><a href="#"><?=fixup($restaurant['heading'])?></a></strong>
<em><?=fixup($preview)?></em>
</p>
</li>
<?php endwhile; ?>
}
?>
If I take out that function the problem goes away.
It is due to your
<?php endwhile; ?>, which closes?>before closing the function’s}, without re-opeining<?php. Since there is no subsequent code inside<?php ?>, the PHP parser sees the remaining stuff outside as plain text output and assumes you have no properly closed the}. It happens that that is the end of the file, and so that is how the error is reported.The
while: / endwhilesyntax is useful for templating where you are primarily mixing HTML with PHP code, but can be confusing when used inside a function like this, as you lose the visual cues provided by open and closed{}groups. I kind of recommend against mixing the syntax in this way.Really, I would recommend against ever closing and reopening
<?php ?>inside a function, but that is a matter of style. Instead, construct the strings that a function outputs andechoorreturnthem.