Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql query - using like <something> and <something='1'> with limit

Tags:

php

mysql

I am being stumped over this problem, and I can't seem to figure it out, hoping someone here can do make heads or tails over this.

When I use the following to query my database:

$q = "SELECT * FROM items WHERE (searchable='1' and title LIKE'%".$_srch."%')";

the items show up they way they are supposed to. But when I add limit 10, 5 to the end:

$q = "SELECT * FROM items WHERE (searchable='1' and title LIKE'%".$_srch."%') limit 10, 5";

The query shows up nothing. I have tried everything I can think of, but I must have missed something. Someone help?

Thanks

like image 921
user3881144 Avatar asked Jan 11 '23 03:01

user3881144


1 Answers

By using LIMIT 10, 5 you're stating that you want the database to start displaying from the 11th row, and display 5 rows. (11th, 12th, 13th, 14th, 15th) - It might be possible that you actually, don't have enough rows.

Try something like, LIMIT 0, 5 - this will display the first 5 rows from the beginning, but 10, 5 will only work if you have more than 10 rows for the search query.

Read more here: http://www.mysqltutorial.org/mysql-limit.aspx

like image 168
Julian Camilleri Avatar answered Jan 12 '23 17:01

Julian Camilleri