Question

I have a query to show all data using PHP and then I have a second query for filtering using startdate and enddate but when I use the second query, the data table shows the first query output plus the second query output.

Here's my code.

Here is my query for the first output:

<?php
session_start();
$con=mysqli_connect("localhost","root","","leavecalendar");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$sql = mysqli_query($con,"SELECT * FROM timekeeping ");
while($row = mysqli_fetch_array($sql))
if(!empty($row)){   

    $_SESSION['row'][] = $row;
header("location:timekeepinglogs.php");
//print_r($_SESSION);
}
//header("location:timekeepinglogs.php");
//print_r($_SESSION);
?>

Here's a screenshot of what the result looks like:

enter image description here

Now here's the second query which is triggered by the generate button

<?php
session_start();
$row = $_SESSION['row'];
$con=mysqli_connect("localhost","root","","leavecalendar");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$sql = mysqli_query($con,"SELECT * FROM timekeeping WHERE createddate >=     '$_POST[startdate]' AND createddate <='$_POST[enddate]' ");
while($row = mysqli_fetch_array($sql))
if(!empty($row)){   

    $_SESSION['row'][] = $row;
//header("location:timekeepinglogs.php");
//print_r($_SESSION);
}
header("location:timekeepinglogs.php");
//print_r($sql);
?>

Now here's what the second query does (notice that in the first picture the last row has empty clockout) I filtered it using date range may 2 to may 3 so it should only show 3 rows. Take a look

enter image description here

As you can see it just select the data in date range and shows it on the bottom of the data table. I want the filtered data only to show.

Any help will be greatly appreciated.

Était-ce utile?

La solution

Probably you are appending the data on each request in table, So you need to clear the sessions data on each new request

Suppose you are searching by dates , before that you need to clear sessions data using

unset($_SESSION['row']);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top