I need help with my website regarding its pagination.
Here's how it work, I search a query, my page gives me its results. Everything is fine so far, but whenever I click on the next page, example page 2, It won't direct me to my next page but instead it will give me an error of:
Notice: Undefined variable: valueToSearch in C:\xampp\htdocs\intern\view-paginated.php on line 72
My first search query works, but only if I click on the next page, suddenly it won't recognize my searched query, basically my pagination just won't work well.
== Source codes ==
Get search query:
if(isset($_POST['search']))
{
$valueToSearch = $_POST['valueToSearch'];
// search in all table columns
// using concat mysql function
$query = "SELECT * FROM `orders` WHERE CONCAT(`KeyAccount`, `BatchNumber`, `Product`, `Quantity`, `PO`, `DateRequested`, `DateDelivered`, `Status`) LIKE '%".$valueToSearch."%'";
$search_result = filterTable($query);
}
else {
$query = "SELECT * FROM `orders`";
$search_result = filterTable($query);
}
// function to connect and execute the query
function filterTable($query)
{
$connect = mysqli_connect("localhost", "root", "", "test");
$filter_Result = mysqli_query($connect, $query);
return $filter_Result;
Defining variables:
$result = mysql_query("SELECT * FROM `orders` WHERE CONCAT(`KeyAccount`, `BatchNumber`, `Product`, `Quantity`, `PO`, `DateRequested`, `DateDelivered`, `Status`) LIKE '%".$valueToSearch."%'");
$total_results = mysqli_num_rows($search_result);
$total_pages = ceil($total_results / $per_page);
Most importantly, Display pagination:
echo "<b>View Page:</b> ";
for ($i = 1; $i <= $total_pages; $i++)
{
echo "<a href='view-paginated.php?page=$i'>$i</a> ";
}
Displaying of results:
echo "<tr>";
echo '<td>' . mysql_result($result, $i, 'KeyAccount') . '</td>';
echo '<td>'. mysql_result($result, $i, 'BatchNumber'). '</td>';
echo '<td>' . mysql_result($result, $i, 'Product') . '</td>';
echo '<td>' . mysql_result($result, $i, 'Quantity') . '</td>';
echo '<td>' . mysql_result($result, $i, 'PO') . '</td>';
echo '<td>' . mysql_result($result, $i, 'DateRequested') . '</td>';
echo '<td>' . mysql_result($result, $i, 'DateDelivered') . '</td>';
echo '<td>' . mysql_result($result, $i, 'Status') . '</td>';
echo '<td><a href="edit.php?id=' . mysql_result($result, $i, 'id') . '">Edit</a></td>';
echo "</tr>";
Thank you in advanced.