跳不出while循环,该怎么解决
跳不出while循环
我想写个分页代码,每个页面显示6种食物,但是好像跳不出循环,不管我进哪一页都是一样的
代码如下:
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$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
------解决方案--------------------
既然你已经计算出起始的偏移,那为什么不用 limit 子句呢
$query .= " limit $page_count_start,6";
$result=queryMysql($query);
同时删除循环中与 $stopwatch 相关的代码
------解决方案--------------------
楼主可能还不知道mysql有limit子句
------解决方案--------------------
在continue;前echo一下,如果看不到echo就是你的判断条件有问题。
另外分页MySQL是使用limit实现的,而不是循环。
------解决方案--------------------
我不是做php的,所以我说的,你选着看吧。
做分页,我的做法是先用count(*)查询一下一共有多少项是要查询的,然后除以每页要显示的条数(item),得到共有多少页(page),然后接收传入的页码数(inpage),如果inpage小于等于0或者为空,则将inpage改为1,如果大于page,则改inpage = page。
设置变量StartPage = (inpage-1)*item,
然后写sql文
select * from tab_name where 条件 limit StartPage,item;
这样就能根据传进来的参数查询了。
在页面,上一页直接用当前页-1,下一页直接用当前页+1,做了上面的处理后,不会出现超出范围的情况了。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The Count function is used to count the number of numbers in a specified range. It ignores text, logical values, and null values, but counts empty cells. The Count function only counts the number of cells that contain actual numbers. The CountA function is used to count the number of non-empty cells in a specified range. It not only counts cells containing actual numbers, but also counts the number of non-empty cells containing text, logical values, and formulas.

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

Implementing data paging and display optimization in Vue projects. In Vue projects, when a page needs to display a large amount of data, data paging and display optimization usually need to be performed to improve user experience. This article will introduce how to use Vue to implement data paging and display optimization. , and provide specific code examples. 1. Data paging Data paging refers to dividing a large amount of data into multiple pages according to certain rules and displaying them on the page. You can use the following steps to implement data paging in a Vue project: Define the data source. First, define a

Introduction Yesterday, a golfer asked me if I could explain to him what the @SpringBootApplication annotation means and how SpringBoot operates, so I took him to browse the source code of this annotation, as well as the run( of the SpringApplication class) ) method, he understood it at once. Don't tell me, the process of looking at the source code is really interesting. No, I discovered an interesting point. publicConfigurableApplicationContextrun(String...args){StopWatchstopWatch=newStopWatch(

This article introduces to you the usage differences of MySQL’s Count function. The need for statistical data is very easy to encounter in our daily development. MySQL also supports a variety of calculation functions. Next, let’s take a look at the differences between them. , and whether they have some pitfalls.

The usage of the count function in PHP is: [count(array,mode);], where the parameter array specifies the array to be counted, and the parameter mode specifies the mode of the function.

Note 1. Count is a terminal operation that can count the total number of elements in the stream. The return value is of long type. 2. count() returns the count of elements in the stream. This is a special case of induction (an induction operation takes a sequence of input elements and combines them into a summary result by repeatedly applying the combining operation). This is a terminal operation and may have consequences and side effects. After a terminal operation is performed, the pipe is considered consumed and cannot be reused. Example // Verify whether there is a string in the list starting with a, and match the first one, that is, return truebooleananyStartsWithA=stringCollection.stream().anyMatch((s

The reproduced test database is as follows: CREATETABLE`test_distinct`(`id`int(11)NOTNULLAUTO_INCREMENT,`a`varchar(50)CHARACTERSETutf8DEFAULTNULL,`b`varchar(50)CHARACTERSETutf8DEFAULTNULL,PRIMARYKEY(`id`))ENGINE= InnoDBAUTO_INCREMENT=1DEFAULTCHARSET=latin1;The test data in the table is as follows. Now we need to count the deduplicated columns of these three columns.
