I am having a pagination for my script that paginates the results based on a search term, but I came up with a small problem.
When the search term is an english string like laptop it works great.
When the word is not english, (greek) even it outputs the correct number of matches found, it shows me only the first page with the 10 results. When I click on page 2 or next, it shows again the correct number of matches but it does not display any of them. If I click from page 2 to page 1, then it shows me again the results of the first page.
So, generally only the first (landing) page works.
I have tested the code before editing to GET a term with a non latin string and did the same ‘wrong’ thing.
This is the url to the tutorial http://papermashup.com/easy-php-pagination/
Thank you for your time and replies.
First of all, you can catch an SQL injection attack with none-escaped input. Then, I think that your search term may break SQL query. Try using mysql_real_escape_string:
The page may only be numerical and then it’s safe to do:
without escaping string.
Then and most important: query for counting and query for data MUST have same JOIns and WHERE parameters. If you search for matches in one table you can get 100 rows. Then you’re trying to JOIN it with another table, where only 10 rows found. You’ll get only 10 rows for data and 100 rows for pages.
And you don’t need to include
AND products.shopid = shops.idto your WHERE clause if you already have it in HAVING clause.Then, the result of your first query is not PAGES count, it’s ROWS count. If you want to show 10 rows on a page, then your total pages count will be
ceiling($total_pages / 10).