2016-10-25 65 views
1

好傢伙一起使用時,我有與MySQL等,並限制指令的問題則返回0空在我的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 
+3

檢索行「這將返回一些成果」 - 有多少? –

+0

任何小於9的值,您將不會得到任何結果,因爲您已將偏移量設置爲9. –

+0

您還需要刪除變量周圍的單引號,在使用預準備語句時不引用值。 – jeroen

回答

0

當你沒有設定限制時,你不會說你得到了多少結果,但我認爲它小於9?

LIMIT 9,9LIMIT 9 OFFSET 9設置了總共9個結果的限制,但從結果編號9開始尋找。如果結果少於9個,則會返回0個結果。我猜你錯誤地理解了限制條款的偏移量部分(這是不需要的)。

刪除OFFSET -part,即使出現LIMIT,您也會得到結果。

0

確保你有足夠的數據滿足LIMIT 9, 9

LIMIT 9, 9手段,從10到18

+0

是的我知道我的目標是在第10行的記錄,所以它應該彈出順便說一句我解決了問題,我不知道它是什麼,我只是解決了它,謝謝任何方式 –

+0

你可以請粘貼你的解決方案? –

+0

$ db = DB :: getInstance(); \t \t $ sql =「SELECT * FROM items where name name LIKE?LIMIT {$ start},9」; \t \t $ results = $ db-> query($ sql,array(「%{$ search}%」)); \t \t $ results = $ results-> results(); \t \t printItems($ results); –