喜欢不能正常使用限制?

时间:2016-10-25 12:32:09

标签: php mysql sql-like

你好伙计们我​​有问题和mysql一样和限制命令一起使用时他们返回0 null我在我的php中尝试了这个然后我去测试它在phpmyadmin里面我得到了相同的结果这里是代码

//mysql

SELECT * FROM `items` WHERE name like '%php%' LIMIT 9,9;  //this return null
SELECT * FROM `items` WHERE name like '%php%' LIMIT 9 OFFSET 9;  //this return null

SELECT * FROM `items` WHERE name like '%php%';//this return some results 

//this is weird please help here is the php code that I use


//php

$db = DB::getInstance();

$results = $db->query("SELECT * FROM `items` WHERE name LIKE ? LIMIT {$start},9",array("'%{$search}%'"));//the query function does the bindvalue

//$start come form $_GET['page'];
//$start equation // $start = ($_GET['page'] * $perpage) - $perpage
//the $perpage is always 9 cause I want to display 9 always or less
//and for sure I check for them if they were set , empty , and escape them etc...

$results = $results->results();

printItems($results);//a function that print items in a special way

2 个答案:

答案 0 :(得分:0)

你没有说你没有设定限制时会得到多少结果,但我认为它不到9?

LIMIT 9,9LIMIT 9 OFFSET 9设置总共9个结果的限制,但从结果编号9 开始查找。如果结果少于9,则返回0结果。我猜你误解了限制条款的偏移部分(不需要)。

删除OFFSET - 部分,即使LIMIT存在,您也会收到结果。

答案 1 :(得分:0)

确保您有足够的数据来满足LIMIT 9, 9

ScheduledExecutorService表示检索10到18之间的行