简体   繁体   中英

While statement timing out

I'm trying to implement pagination for a search result. The following code works perfectly:

        echo "<p>" . $data['meta']['total'] . " properties found. (search " . $data['meta']['searchId'] . ")</p>\n";

        $pages = $data['meta']['total'] / $count;
        $pages = ceil($pages);

        echo "<p>" . $pages . "</p>\n";

However, if I add in the following, I get a timeout:

        $page = 1;

        echo "<p>";
        while ($page <= $pages); {
            echo $page++ . " ";
        }
        echo "</p>\n";

No doubt I'm missing something obvious.

Your error is here:

while ($page <= $pages); {
                     //^ See this empty statement here!
    echo $page++ . " ";
}

Your while loop loops trough a empty statement so no statement is going to increment $page . So your curly brackets are just a normal code block, in order to get your while loop working just remove the semicolon like this:

while ($page <= $pages) {
    echo $page++ . " ";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM