Cannot jump out while loop, how to solve

Source: Internet
Author: User
Cannot jump out while loop
I want to write a paging code that shows 6 kinds of food on each page, but it doesn't seem to jump out of the loop, no matter which page I'm in.
The code is as follows:
PHP Code
  $each _page=6;            $diff = $rows% 6;            $page _org= $rows/6;            $count = 1;            if ($diff >0) {$page = floor ($page _org+1);            } else {$page = floor ($page _org);            } $page _count_start=0;            $page _count_end=0;            $stopwatch = 0; if (!isset ($_get[' page ')) | |                (Isset ($_get[' page ')) &&$_get[' page ') ==1) {//echo "Hello";                $page _num=1;            $page _count_end= $page _count_start + 6;                } else {//echo "Hello";                $page _num=$_get[' page ';                $page _count_start= $page _num + ($page _num-1) * 5;            $page _count_end= $page _count_start + 6;            } $query = "select * from DISH where dish_id in (select dish_id from Category_menu where cat_id= $cat _id)";                        $result =querymysql ($query); While($get _details=mysql_fetch_array ($result))                {$stopwatch + +;                    if ($stopwatch < $page _count_start) {//$stopwatch + +;   Continue                It seems to not jump out here, try, regardless of which page is the same} $dish _id= $get _details[' dish_id ';                $dish _price= $get _details[' Dish_price ';                $dish _name= $get _details[' dish_name ';                $dish _img= $get _details[' Img_url ';                $dish _descr= $get _details[' dish_description ';                            echo "$dish _id $stopwatch";                $page _count_start++;                    if ($page _count_start== $page _count_end+1) {$stopwatch = 0;                Break }//echo "...";}



------Solution--------------------
Now that you have calculated the initial offset, why not use the limit clause?
$query. = "Limit $page _count_start,6";
$result =querymysql ($query);

Delete the $stopwatch-related code in the loop at the same time
------Solution--------------------
Landlord may not know that MySQL has a limit clause
------Solution--------------------
In continue, before Echo, if you don't see echo, you have a problem with your judging condition.
In addition, paging MySQL is implemented using limit instead of looping.
------Solution--------------------
I do not do PHP, so I said, you choose to see it.
To do pagination, my practice is to use COUNT (*) to find out how many items are to be queried, then divide by the number of bars per page to display (item), how many pages are in total (page), and then receive the number of page numbers (InPage) passed in, if InPage is less than or equal to 0 or empty, Change the inpage to 1 if it is greater than page, then InPage = page.
Set Variable StartPage = (inpage-1) *item,
Then write the SQL text
SELECT * from tab_name where condition limit startpage,item;
This can be based on the parameters passed in the query.
On the page, the previous page directly with the current page-1, the next page directly with the current page +1, do the above processing, will not appear beyond the scope of the situation.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.