Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
CREATE TABLE customer (
id int,
name varchar(64)
);
INSERT INTO customer VALUES
(1, 'Customer1'),
(2, 'Customer2'),
(3, 'Customer3'),
(5, 'Customer5');
<?php
// include "conn.php";
$conn = &$mysqli;
$limit = 5;
$fetch = mysqli_query($conn, "select * from customer");
$total_rows = mysqli_num_rows($fetch);
$total_pages = ceil($total_rows / $limit);
if (!isset($_GET["page"])) {
$page_number = 1;
} else {
$page_number = (int)$_GET["page"];
}
$initial_page = ($page_number - 1) * $limit;
$fetch = "SELECT * FROM customer LIMIT " . $initial_page . "," . $limit;
if (isset($_GET["submit"])) {
$search = $_GET["search"];
if (empty($search)) {
echo "empty";
} else {
$fetch =
"SELECT *FROM customer where name LIKE '$search%' OR phonenumber LIKE '$search%' OR email LIKE '$search%'OR country LIKE '$search%' LIMIT " .
$initial_page .
"," .
$limit;
}
}
$result = mysqli_query($conn, $fetch);
while ($row = $result -> fetch_assoc()) {
print_r($row);
}