Created
April 15, 2019 18:29
-
-
Save Carlosvva/205ad47b1730c7526145b451ad9614d4 to your computer and use it in GitHub Desktop.
Codigo fuente
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//fetch.php | |
$connect = mysqli_connect("localhost", "root", "", "4am_traficon"); | |
$columns = array('codordint', 'codcli', 'trabajo', 'f_ingresa', 'f_solicita', 'f_entrega', 'codstat'); | |
$query = "SELECT * FROM ordint WHERE "; | |
if($_POST["is_date_search"] == "yes") | |
{ | |
$query .= 'f_aprueba BETWEEN "'.$_POST["start_date"].'" AND "'.$_POST["end_date"].'" AND '; | |
} | |
if(isset($_POST["search"]["value"])) | |
{ | |
$query .= ' | |
(codordint LIKE "%'.$_POST["search"]["value"].'%" | |
OR codcli LIKE "%'.$_POST["search"]["value"].'%" | |
OR trabajo LIKE "%'.$_POST["search"]["value"].'%" | |
OR f_ingresa LIKE "%'.$_POST["search"]["value"].'%") | |
OR f_solicita LIKE "%'.$_POST["search"]["value"].'%") | |
OR f_entrega LIKE "%'.$_POST["search"]["value"].'%") | |
OR codstat LIKE "%'.$_POST["search"]["value"].'%") | |
'; | |
} | |
if(isset($_POST["order"])) | |
{ | |
$query .= 'ORDER BY '.$columns[$_POST['order']['0']['column']].' '.$_POST['order']['0']['dir'].' | |
'; | |
} | |
else | |
{ | |
$query .= 'ORDER BY codordint DESC '; | |
} | |
$query1 = ''; | |
if($_POST["length"] != -1) | |
{ | |
$query1 = 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length']; | |
} | |
$number_filter_row = mysqli_num_rows(mysqli_query($connect, $query)); | |
$result = mysqli_query($connect, $query . $query1); | |
$data = array(); | |
while($row = mysqli_fetch_array($result)) | |
{ | |
$sub_array = array(); | |
$sub_array[] = $row["codordint"]; | |
$sub_array[] = $row["codcli"]; | |
$sub_array[] = $row["trabajo"]; | |
$sub_array[] = $row["f_ingresa"]; | |
$sub_array[] = $row["f_solicita"]; | |
$sub_array[] = $row["f_entrega"]; | |
$sub_array[] = $row["codstat"]; | |
$data[] = $sub_array; | |
} | |
function get_all_data($connect) | |
{ | |
$query = "SELECT * FROM ordint"; | |
$result = mysqli_query($connect, $query); | |
return mysqli_num_rows($result); | |
} | |
$output = array( | |
"draw" => intval($_POST["draw"]), | |
"recordsTotal" => get_all_data($connect), | |
"recordsFiltered" => $number_filter_row, | |
"data" => $data | |
); | |
echo json_encode($output); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>orders whti</title> | |
<script src="https://code.jquery.com/jquery-1.12.4.js"></script> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" /> | |
<script src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script> | |
<script src="https://cdn.datatables.net/1.10.15/js/dataTables.bootstrap.min.js"></script> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker.css" /> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.js"></script> | |
<style> | |
body | |
{ | |
margin:0; | |
padding:0; | |
background-color:#f1f1f1; | |
} | |
.box | |
{ | |
width:1270px; | |
padding:20px; | |
background-color:#fff; | |
border:1px solid #ccc; | |
border-radius:5px; | |
margin-top:25px; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="container box"> | |
<h1 align="center">-</h1> | |
<br /> | |
<div class="table-responsive"> | |
<br /> | |
<div class="row"> | |
<div class="input-daterange"> | |
<div class="col-md-4"> | |
<input type="text" name="start_date" id="start_date" class="form-control" placeholder="Fecha de inicio" /> | |
</div> | |
<div class="col-md-4"> | |
<input type="text" name="end_date" id="end_date" class="form-control" placeholder="Fecha de final" /> | |
</div> | |
</div> | |
<div class="col-md-4"> | |
<input type="button" name="search" id="search" value="Buscador" class="btn btn-info" /> | |
</div> | |
</div> | |
<br /> | |
<table id="order_data" class="table table-bordered table-striped"> | |
<thead> | |
<tr> | |
<th>codordint</th> | |
<th>codcli</th> | |
<th>trabajo</th> | |
<th>f_ingresa</th> | |
<th>f_solicita</th> | |
<th>f_entrega</th> | |
<th>codstat</th> | |
</tr> | |
</thead> | |
</table> | |
</div> | |
</div> | |
</body> | |
</html> | |
<script type="text/javascript" language="javascript" > | |
$(document).ready(function(){ | |
$('.input-daterange').datepicker({ | |
todayBtn:'linked', | |
format: "yyyy-mm-dd", | |
autoclose: true | |
}); | |
fetch_data('no'); | |
function fetch_data(is_date_search, start_date='', end_date='') | |
{ | |
var dataTable = $('#order_data').DataTable({ | |
"processing" : true, | |
"serverSide" : true, | |
"order" : [], | |
"language": { | |
"url": "//cdn.datatables.net/plug-ins/1.10.19/i18n/Spanish.json" | |
}, | |
"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "Todas"]], | |
"ajax" : { | |
url:"fetch.php", | |
type:"POST", | |
data:{ | |
is_date_search:is_date_search, start_date:start_date, end_date:end_date | |
} | |
} | |
}); | |
} | |
$('#search').click(function(){ | |
var start_date = $('#start_date').val(); | |
var end_date = $('#end_date').val(); | |
if(start_date != '' && end_date !='') | |
{ | |
$('#order_data').DataTable().destroy(); | |
fetch_data('no', start_date, end_date); | |
} | |
else | |
{ | |
alert("Both Date is Required"); | |
} | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment