mysqli_fetch_array在特定行上开始查询 [英] mysqli_fetch_array starting the query on a certain row

查看:104
本文介绍了mysqli_fetch_array在特定行上开始查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在某些页面上创建分页,这些页面显示MySQL表中的行.每个页面显示表中的六个项目.我正在使用while循环:

I am trying to create pagination on some pages that display rows from a MySQL table. Each page displays six items from the table. I am using a while loop with:

$row_users = mysqli_fetch_array($result_users, MYSQL_NUM);

它将一直循环遍历结果,直到没有更多为止(我会提供完整的代码,但这是大量元素的一部分).我的网页ID中有一个GET变量:

It just keeps looping through the results until there are no more (I would include the full code but it's part of a very large amount of elements). I have a GET variable from the page id as:

$page = $_GET['page'];

基本上,我想在每个页面的特定行上启动读取数组.例如,在 http://www.example.com?page=2 上,我想要从表的第十三行(($ page * 6)+1)开始.

Basically I want to start the fetch array on the specific row for each page. For example on http://www.example.com?page=2 I would like it to start on the thirteenth row of the table (($page*6)+1).

我的问题是,如何获取fetch_array从某一行开始?我看到了这篇文章: Mysqli获取数组的第n行,但这只是处理特定的行,而不是开始循环并继续经过该行.我似乎找不到在任何地方执行此操作的方法.也许我在搜索错误的东西...感谢您的帮助!

My question is, how do I get a fetch_array to start on a certain row? I saw this post: Mysqli fetch array nth row but that just deals with grabbing the specific row, not starting the loop and continuing on past that row. I can't seem to find the method of doing this anywhere. Perhaps I'm Googling the wrong thing...thanks for your help!

推荐答案

与其在获取它们时不尝试跳过不需要的行,还不如告诉MySQL不要产生那些行,这样效率更高.在SELECT查询的末尾使用LIMIT子句,以使MySQL仅产生所需的行:

Rather than trying to skip the rows you don't want while fetching them, it's more efficient to tell MySQL not to produce those rows. Use the LIMIT clause at the end of your SELECT query to have MySQL only produce the rows you need:

http://dev.mysql.com/doc/refman/5.0/en/select.html

这篇关于mysqli_fetch_array在特定行上开始查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆