0
How to do pagination in PHP in a search result?
Hello Everyone! I'm a PHP beginner so I'm a bit confuse. Someone pliz I mean plizzzzzzzzz explain how to paginate the results from my search engine in PHP. I'm dying my brain is going to blast. I don't want only the code but also the explanation. If there is someone willing to help me pliz do becoz I mean it. Thank you.
6 Antworten
+ 2
@Vincent
okey I'll try everytime I click the pagination link like page 2 it didn't saw anything. Work fine once.
$sql = "Select * from users WHERE name LIKE '% ".mysqli_real_escape_string($_GET['keyword"])."%' LIMIT start_limit,end_limit";
+ 1
@Vincent
thanks Bro!
I did it now.
what a fool am I.haha
0
it's pretty simple.
- make a variable that tells wich page you're on : $page = $_GET['page']
- add the LIMIT instruction to your SQL query :
$sql .= 'LIMIT ' . $page* $x, $x
$x is the number of result par page
Then you print links to access each page ; get count of all your articles and divide it by $x.
it's a simple problem, you really should try to solve it yourself before getting all made code
0
@Vincent
I want to submit the keyword from a search engine.
You know what I mean?
0
yes. i assumed you are not starting from scratch and at least can list your content, whatever it is, am i right ?
0
your loop for print links should be something like this :
$nbUsers = 125;
$usersPerPage = 7;
$page = 0;
$nbPages = ceil($nbUsers / $usersPerPage);
do{
echo "link.php?page=" . $page++;
} while ($page < $nbPages);
please mind that i couldn't test this code, it should gave you an idea of what to do.