English 中文(简体)
MySQL:在问询中,我需要获得一个项目的抵销。
原标题:MySQL: I need to get the offset of a item in a query

Mysql:i need to have the supplemented of a items in a query.

我有一张画面:这张画面显示每栏6个图像,因此,当我要求图像22时,图像从18个显示到24个。 它应首先得到图像22的抵消,然后从18个到24个。

另外一个例子:一是要求图像编号62(并抵消62),它将选择图像,从60个减少到66个。

是否可能有一个单一问题?

www.un.org/Depts/DGACM/index_spanish.htm 最重要的事情是获得该项目的抵消价值,其数量相当于。

感谢;

EDIT: select * from images order_by updated_at offset(here i need to get the offset of the image id in this query, and the make some calculation... this is what i need, if is possible.. :d)

EDIT2: Now I understand that I need 2 queries:

页: 1

2o:利用第一个问题所抵消的图像......我可以单独制作,第一个问题是问题。

最佳回答

如果您的图像有顺序识别,你可能想做以下工作:

SELECT    * 
FROM      images 
WHERE     id >= ((? DIV 6) * 6) AND 
          id < (((? DIV 6) + 1) * 6)
ORDER BY  id;

将<代码>改为: para amount in the above query with the ID of the culture requested.


<><>UPDATE: 看来,你的图像不是由顺序编号来定的,而是用时间顺序排列的。 遗憾的是,它喜欢MySQL并不支持LIMIT条款(。 一种选择是使用准备声明:

PREPARE stmt FROM 
" SELECT    * 
  FROM      images
  ORDER BY  updated_at
  LIMIT     ?, 6";

SET @lower_limit := ((22 DIV 6) * 6);

EXECUTE stmt USING @lower_limit;

另一种选择是:

SET @row = 0;

SELECT    * 
FROM      images 
WHERE     (@row := @row + 1) BETWEEN ((3 DIV 6) * 6) + 1 and (((3 DIV 6) + 1) * 6)
ORDER BY  updated_at;
问题回答

我也许不理解你,但为什么你必须做我的我的我的我的我的我的我的我的我的我的我的吗?

让我们承担起利用LAMP:

$pagination_start = (int)(floor($id_requested / 6)*6);
$offset_array = ($id_requested % 6);
$offset_mysql = $pagination_start + $offset_array;

现在,你开始在<代码> $-开始<>/code>[i.e. 60]上进行想象,并要求在上对图像进行校正:

SELECT   image
FROM     images
ORDER BY updated_at DESC
LIMIT    $pagination_start, 6

现在,你们得到一阵列的6个图像,而请求的图像则在<代码>后得出。

SELECT   image
FROM     images
ORDER BY updated_at
LIMIT    6, FLOOR($number / 6 ) * 6;




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签