Php Folks,
When I click the SEARCH button. 5 matching rows found from my mysql db.
Note this:
[code]
$_SESSION[‘row_count’] = 5;
Then when I click PAGE 2 on pagination section, it should still be: $_SESSION[‘row_count’] = 5.
But not! It is:
[code]
$_SESSION[‘row_count’] = 0;
Why is that ? It should stay ‘5’. Right ? I am not overwriting the variable value either.
This is the reason why, when I click PAGE 2 or PAGE 3 (any pages after PAGE 1) on the PAGINATION section, I see zero results or no rows shown. No rows get shown beyond page 1. Why ?
If I can find-out why the ‘$_SESSION[‘row_count’] = 5′ auto becomes $
Look, after clicking the SEARCH button, this part of my code yields $_SESSION[‘row_count’] = 5. So far so good.
[code]
$query_1 = “SELECT COUNT(id) FROM users WHERE first_name = ? AND marital_status = ?”;
$stmt_1 = mysqli_stmt_init($conn);
if(mysqli_stmt_prepare($stmt_1,$query_1))
{
mysqli_stmt_bind_param($stmt_1,”ss”,$_POST[“first_name”],$_POST[“marital_status”]);
mysqli_stmt_execute($stmt_1);
$result_1 = mysqli_stmt_bind_result($stmt_1,$row_count);
mysqli_stmt_fetch($stmt_1);
$_SESSION[‘row_count’] = $row_count;
NOTE:
I get shown the matching rows on PAGE 1. Since I set it to display 1 row per page, I am shown 1 matching row. So far, so good.
Now, when I click PAGE 2 on the PAGINATION section, I expect to see the 2nd matching row, but “$_SESSION[‘row_count’] = 5″ switches to “$
This illegal switching ruins this following query that runs when I click PAGE 2 or any PAGE (eg PAGE 3) beyond PAGE 1:
[code]
$row_count = $_SESSION[‘row_count’];
//$total_pages = ceil($result_1/$result_per_page); //Should I keep this line or the line below ? Which one ?
$total_pages = ceil($row_count/$result_per_page); //Should I keep this line or the line above it ? Which one ?
I need an answer to my question on the comment above.
Context:
[code]
$query_1 = “SELECT COUNT(id) FROM users WHERE first_name = ? AND marital_status = ?”;
$stmt_1 = mysqli_stmt_init($conn);
if(mysqli_stmt_prepare($stmt_1,$query_1))
{
mysqli_stmt_bind_param($stmt_1,”ss”,$_POST[“first_name”],$_POST[“marital_status”]);
mysqli_stmt_execute($stmt_1);
$result_1 = mysqli_stmt_bind_result($stmt_1,$row_count);
mysqli_stmt_fetch($stmt_1);
$_SESSION[‘row_count’] = $row_count; // $row_count = 5, here.
On the above code, check my comment!
[code]
$query_2 = “SELECT id,first_name,middle_name,surname,gender,marital_status,working_status FROM users WHERE first_name = ? AND marital_status = ? ORDER by id LIMIT $offset,$last_row_on_page”;
$stmt_2 = mysqli_stmt_init($conn);
if(mysqli_stmt_prepare($stmt_2,$query_2))
mysqli_stmt_bind_param($stmt_2,”ss”,$_POST[“first_name”],$_POST[“marital_status”]);
mysqli_stmt_execute($stmt_2);
$result_2 = mysqli_stmt_get_result($stmt_2);
//Grab total number of pages to paginate.
$row_count = $_SESSION[‘row_count’]; //Why this value switched from ‘5’ to ‘0’ here ?
//$total_pages = ceil($result_1/$result_per_page);
$total_pages = ceil($row_count/$result_per_page);
On the above code, check my comment as I need it’s question answered!