Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8955317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:31:30+00:00 2026-06-15T14:31:30+00:00

Ok, I have looked over and over this code but I can’t seem to

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:31:31+00:00Added an answer on June 15, 2026 at 2:31 pm

    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.

    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; // Don't close ?> here!
    

    The while: / endwhile syntax 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 and echo or return them.

    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);
    
        $html = "";
        while ($restaurant = mysql_fetch_array($restresult)) {
            // Trim article for preview 
            // You can't call functions in the HEREDOC, so call them here first
            $preview = fixup(trim_str($restaurant['fullarticle'], 270));
            $heading = fixup($restaurant['heading']);
    
            // Build the string with a HEREDOC, insead of directly sending it to the output buffer
            // by closing ?> and reopening <?php
            $html .=<<<HTMLSTRING
            <li>
                <img alt="$heading" src="images/frontpage/{$restaurant['bigimage']}" width="615" height="309" />
                <a href="#" class="read-more">Read More</a>
                <p>         
                    <strong><a href="#">$heading</a></strong>
                    <em>$preview</em>               
                </p>
            </li>
    HTMLSTRING;
    // No whitespace before the closing of the HEREDOC!
        }
        // Then echo the HTML output
        echo $html;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have looked all over the net but still can get this right. the
This may have been posted here somewhere but I can't find it. I am
I have looked all over and cannot figure out why this code isn't working.
I have looked all over the web and I can not find the information
I've looked over this code a zillion times and can't see anything wrong with
I have looked everywhere and surprisingly can't find a good solution to this! I've
I've already looked at the other SO discussions but can't seem to find an
I have looked all over the internet to find an answer to my problem
I've looked a lot into this, but I can only seem to get webView
I know this is frequently asked, but I have looked all over the internet

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.