-2

When I search then All rows/querys display. That's why page loading is too slow.

I want to show only 100 rows/querys with paging when I will search something.

or make it faster if any modification need.

Please

$sql = "SELECT * FROM crawl WHERE title LIKE '%".$strKeyword."%' "; $query = mysqli_query($conn,$sql);

$num_rows = mysqli_num_rows($query);

$per_page = 2;   // Per Page $page  = 1;

if(isset($_GET["Page"])) {  $page = $_GET["Page"]; }

$prev_page = $page-1; $next_page = $page+1;

$row_start = (($per_page*$page)-$per_page); if($num_rows<=$per_page) {  $num_pages =1; } else if(($num_rows % $per_page)==0) {  $num_pages
=($num_rows/$per_page) ; } else {   $num_pages =($num_rows/$per_page);  $num_pages = (int)$num_pages; } $row_end = $per_page * $page; if($row_end > $num_rows) {    $row_end = $num_rows; }

$sql .= "ORDER BY id, title, ogimage DESC LIMIT $row_start ,28 "; $query = mysqli_query($conn,$sql);
  • 1
    Your code is a bit chaotic, and some of it makes little sense. This is probably why noone reacts to your question. Why not start by cleaning up your code? Remove stuff that's not needed, make it readable by properly indenting it. Put stuff that belongs together together, perhaps even use a function here and there? – KIKO Software Feb 23 '22 at 09:39
  • **Warning:** You are wide open to [SQL Injections](https://php.net/manual/en/security.database.sql-injection.php) and should use parameterized **prepared statements** instead of manually building your queries. They are provided by [PDO](https://php.net/manual/pdo.prepared-statements.php) or by [MySQLi](https://php.net/manual/mysqli.quickstart.prepared-statements.php). Never trust any kind of input! Even when your queries are executed only by trusted users, [you are still in risk of corrupting your data](http://bobby-tables.com/). [Escaping is not enough!](https://stackoverflow.com/q/5741187) – Dharman Feb 23 '22 at 14:42

1 Answers1

0
  • LIKE starting with a wild card is slow because it cannot use an index
  • FULLTEXT, together with MATCH is much faster, but has limitations.
  • "Computing" which rows to OFFSET has several problems, including performance.

See Pagination

Rick James
  • 135,179
  • 13
  • 127
  • 222