Php, Mysql从表中选择row = ?它是可能的吗?

时间:2021-03-11 22:16:35

Hello I want to get select query with send row record number

你好,我想用发送行记录号获取select查询

 $row = 3;
 SELECT FROM clients WHERE ROW()=$row ORDER BY ID DESC 

it is possible ? How can i do that ?

它是可能的吗?我怎么做呢?

3 个解决方案

#1


4  

If you want the third row, use offset/limit:

如果你想要第三行,使用偏移/限制:

select *
from clients
order by id
offset 2
limit 1;

Note that that offset 0 gets the first record, so offset 2 would be the third record.

注意,偏移量0获得第一个记录,因此偏移量2将是第三个记录。

#2


0  

You need to use LIMIT instead of WHERE

你需要用极限而不是在哪里

If you want get a row with N position, you can try this:

如果你想得到一个有N个位置的行,你可以试试这个:

SELECT * FROM clients LIMIT N-1,1

So if you want get third row you need to use something like this:

所以如果你想要得到第三行你需要像这样:

SELECT * FROM clients LIMIT 2,1

#3


0  

This is what i would do.. entry_id is unique and 1 = first row, 2 = second row, etc..

这就是我要做的。entry_id是唯一的,1 =第一行,2 =第二行,等等。

entry_id is set as primary index and auto increase..

entry_id | what | ever | records
1 | a | b | c
2 | a | b | c
3 | b | c | a
4 | a | b | c
5 | a | b | c

$row = 3;

Select * From clients Where entry_id = $row

returns third row, 3, b, c, a

返回第三行,3 b c a

#1


4  

If you want the third row, use offset/limit:

如果你想要第三行,使用偏移/限制:

select *
from clients
order by id
offset 2
limit 1;

Note that that offset 0 gets the first record, so offset 2 would be the third record.

注意,偏移量0获得第一个记录,因此偏移量2将是第三个记录。

#2


0  

You need to use LIMIT instead of WHERE

你需要用极限而不是在哪里

If you want get a row with N position, you can try this:

如果你想得到一个有N个位置的行,你可以试试这个:

SELECT * FROM clients LIMIT N-1,1

So if you want get third row you need to use something like this:

所以如果你想要得到第三行你需要像这样:

SELECT * FROM clients LIMIT 2,1

#3


0  

This is what i would do.. entry_id is unique and 1 = first row, 2 = second row, etc..

这就是我要做的。entry_id是唯一的,1 =第一行,2 =第二行,等等。

entry_id is set as primary index and auto increase..

entry_id | what | ever | records
1 | a | b | c
2 | a | b | c
3 | b | c | a
4 | a | b | c
5 | a | b | c

$row = 3;

Select * From clients Where entry_id = $row

returns third row, 3, b, c, a

返回第三行,3 b c a