<?php
session_start();
if (!isset($_SESSION['username'])) {
    echo "<script>window.top.location.href='index.php';</script>"; // Redirect parent window to login page
    exit();
}

include 'connect.php';

$search = isset($_POST['search']) ? mysqli_real_escape_string($conn, $_POST['search']) : '';

// Get total records count
$total_sql = "SELECT COUNT(*) as total FROM products_table WHERE pr_Name LIKE '%$search%'";
$total_result = mysqli_query($conn, $total_sql);
$total_row = mysqli_fetch_assoc($total_result);
$total_records = $total_row['total'];
$total_pages = ceil($total_records / 10); // 10 records per page

for ($i = 1; $i <= $total_pages; $i++) {
    echo '<li class="page-item ' . ($i == 1 ? 'active' : '') . '">
        <a class="page-link" href="#" data-page="' . $i . '"> ' . $i . ' </a>
    </li>';
}
?>
