Jump to content

Filtrar tabela por intervalo de datas


Joel Tavares Martins

Recommended Posts

O meu objetivo era criar uma tabela com dados e depois filtrar os dados por um intervalo de datas.

Código HTML:

echo"<form action='table.php' method='post' >";
echo"<div class='card-body pt-0'>";
echo"<div class='card-title'>";
echo"<div class=' search d-flex align-items-center position-absolute my-1'>
		<span class='svg-icon svg-icon-1 position-absolute ms-6'>
			<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='24px' height='24px' viewBox='0 0 24 24' version='1.1'>
				<g stroke='none' stroke-width='1' fill='none' fill-rule='evenodd'>
					<rect x='0' y='0' width='24' height='24'></rect>
					<path d='M14.2928932,16.7071068 C13.9023689,16.3165825 13.9023689,15.6834175 14.2928932,15.2928932 C14.6834175,14.9023689 15.3165825,14.9023689 15.7071068,15.2928932 L19.7071068,19.2928932 C20.0976311,19.6834175 20.0976311,20.3165825 19.7071068,20.7071068 C19.3165825,21.0976311 18.6834175,21.0976311 18.2928932,20.7071068 L14.2928932,16.7071068 Z' fill='#000000' fill-rule='nonzero' opacity='0.3'></path>
					<path d='M11,16 C13.7614237,16 16,13.7614237 16,11 C16,8.23857625 13.7614237,6 11,6 C8.23857625,6 6,8.23857625 6,11 C6,13.7614237 8.23857625,16 11,16 Z M11,18 C7.13400675,18 4,14.8659932 4,11 C4,7.13400675 7.13400675,4 11,4 C14.8659932,4 18,7.13400675 18,11 C18,14.8659932 14.8659932,18 11,18 Z' fill='#000000' fill-rule='nonzero'></path>
				</g>
			</svg>
		</span>
        <input type='text' name='valueToProcurar' class='form-control form-control-solid w-250px ps-15' placeholder='Search Customers'>
        <button type='submit' name='procura' value='Filter' class='btn btn-primary' data-kt-menu-dismiss='true' data-kt-customer-table-filter='filter'>Procurar nome</button>
        </div>";
	echo"<div class='d-flex justify-content-end' data-kt-customer-table-toolbar='base'>";
		echo"<button type='button' class='btn btn-light-primary me-3' data-kt-menu-trigger='click' data-kt-menu-placement='bottom-end' data-kt-menu-flip='top-end'>";
			echo"<span class='svg-icon svg-icon-2'>";
				echo"<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='24px' height='24px' viewBox='0 0 24 24' version='1.1'>";
					echo"<g stroke='none' stroke-width='1' fill='none' fill-rule='evenodd'>";
						echo"<rect x='0' y='0' width='24' height='24' />
						<path d='M5,4 L19,4 C19.2761424,4 19.5,4.22385763 19.5,4.5 C19.5,4.60818511 19.4649111,4.71345191 19.4,4.8 L14,12 L14,20.190983 C14,20.4671254 13.7761424,20.690983 13.5,20.690983 C13.4223775,20.690983 13.3458209,20.6729105 13.2763932,20.6381966 L10,19 L10,12 L4.6,4.8 C4.43431458,4.5790861 4.4790861,4.26568542 4.7,4.1 C4.78654809,4.03508894 4.89181489,4 5,4 Z' fill='#000000' />";
					echo"</g>";
				echo"</svg>";
			echo"</span>";
            echo"Filtro</button>";
			echo"<div class='menu menu-sub menu-sub-dropdown w-300px w-md-325px' data-kt-menu='true'>";
			echo"<div class='px-7 py-5'>";
				echo"<div class='fs-4 text-dark fw-bolder'>Filter Options</div>";
			echo"</div>";
			echo"<div class='separator border-gray-200'></div>";
			echo"<div class='px-7 py-5'>";
					echo"<div>";
						echo"<p> <b>Data</b> </p>
						<label for='from'>From</label> 
						<input type='date' id='datepicker' name='fromDate' placeholder='Value To Search'>
						<br><br>
						<label for='to'>to</label> 
						<input type='date' id='datepicker2' name='toDate' placeholder='Value To Search'>
						<br><br>";
					echo"</div>";

					echo"<div class='d-flex justify-content-end'>";
						echo"<button type='reset' class='btn btn-white btn-active-light-primary me-2' data-kt-menu-dismiss='true' data-kt-customer-table-filter='reset'>Reset</button>
						<button type='submit' name='procura' value='Filter' class='btn btn-primary' data-kt-menu-dismiss='true' data-kt-customer-table-filter='filter'>Apply</button>";
					echo"</div>";
				echo"</div>";
			echo"</div>";
		echo"</div>";
		echo"<div class='d-flex justify-content-end align-items-center d-none' data-kt-customer-table-toolbar='selected'>";
			echo"<div class='fw-bolder me-5'>";
                echo"<span class='me-2' data-kt-customer-table-select='selected_count'></span>Selected</div>";
                echo"<button type='button' class='btn btn-danger' data-kt-customer-table-select='delete_selected'>Delete Selected</button>";
            echo"</div>";
		echo"</div>";
    echo"<div class='table-responsive'>";
echo"<table class='table align-middle table-row-dashed fs-6 gy-5 dataTable no-footer' id='kt_customers_table myTable' role='grid'>";
echo"<thead>";
echo"<tr class='text-start text-gray-400 fw-bolder fs-7 text-uppercase gs-0'><th class='w-10px pe-2'><div class='form-check form-check-sm form-check-custom form-check-solid me-3'><input class='form-check-input' type='checkbox' data-kt-check='true' data-kt-check-target='kt_customers_table .form-check-input' value='1' /></div></th><th class='min-w-125px'>id</th><th class='min-w-125px'>Nome</th><th class='min-w-125px'>Website</th><th class='min-w-125px'>Email</th><th class='min-w-125px'>Serviço</th><th class='min-w-125px'>Data</th><th class='min-w-125px'>Montante</th><th class='text-end min-w-70px'>Delete</th></tr>";
echo"</thead>";
while($row = mysqli_fetch_array($search_result)) {
    echo"<tbody class='fw-bold text-gray-600'>
    <tr class='container' id='gfg'>
        <td> <div class='form-check form-check-sm form-check-custom form-check-solid'><input class='form-check-input' type='checkbox' value='1' /></div></td>
        
        <td>{$row['id']}</td>

        <td> {$row['nome']} </td>

        <td> {$row['website']} </td>

        <td> {$row['email']} </td>

        <td> {$row['serv']} </td>

        <td> {$row['data']} </td>

        <td class='text-gray-800 text-hover-primary mb-1'> {$row['montante']} </td>
        <td class='text-end'>
        <div class='menu-item px-3'>
            <a href='dist/apps/costumers/delete.php?id=".$row['id']."'  class='menu-link px-3' >Delete</a>
        </div>
        </td>
    </tr>
</tbody>";
}
echo"</table>";
echo"</div>";
echo"</form>";
echo"</div>";
echo"</div>";
echo"<div>
		<script src='dist/assets/plugins/global/plugins.bundle.js'></script>
		<script src='dist/assets/js/scripts.bundle.js'></script>
        <script src='dist/assets/plugins/custom/datatables/datatables.bundle.js'></script>
        <script src='dist/assets/js/custom/apps/customers/list/export.js'></script>
		<script src='dist/assets/js/custom/apps/customers/list/list.js'></script>
		<script src='dist/assets/js/custom/apps/customers/add.js'></script>
		<script src='dist/assets/js/custom/widgets.js'></script>
		<script src='dist/assets/js/custom/apps/chat/chat.js'></script>
		<script src='dist/assets/js/custom/modals/create-app.js'></script>
		<script src='dist/assets/js/custom/modals/upgrade-plan.js'></script>
        <script src='dist/assets/js/custom/intro.js'></script>

</div>";
echo"</hmtl>";

Código PHP:

<?php
require'a/connect.php';

$trueuser="usermix";
$truepass="user0000";

$username = $_GET["username"];
$password = $_GET["password"];

if($username == $trueuser and $password == $truepass)
{
    header("location: table.php");
}
else
    {
        if($username == $trueuser and $password != $truepass)
        {
            echo'WRONG PASSWORD !!!
            Login Failed.';
        }
        else
            {
                if($username != $trueuser and $password == $truepass)
                {
                    echo'WRONG USERNAME !!!
                    Login Failed.';
                }
                else
                    {
                        if($username != $trueuser and $password != $truepass)
                        {
                            echo'WRONG PASSWORD AND USERNAME !!!
                            Login Failed.';
                        }
                    }
            }
    }

?>

Eu já tenho o filtro por nome, agora queria inserir um filtro por intervalo de datas mas quando insiro as datas não acontece nada.

Agradeço toda a ajuda possível.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.