Datatable using mysqli with a select WHERE $_GET from a previous form
Datatable using mysqli with a select WHERE $_GET from a previous form
Hi, i have a datatable using a previous form and i want to show the articles i have inside an order so i use GET to get the ID of the order and show the data, but dont work if i use GET method.Can help me please?
testlist,php?codov=22222 is the url when i submit de form
testlist.php
<script type="text/javascript">
$(document).ready(function() {
var url = window.location.href;
var arguments = url.split('?').pop().split('=').pop();
listar();
});
var listar = function(){
var table = $('#mytable').DataTable({
"bProcessing": true,
"sAjaxSource": "test.php?codov="+arguments,
"aoColumns": [
{ mData: 'CodArt' } ,
{ mData: 'NombreArt' }
]
});
}
</script>
</head>
<body>
<table id="mytable" class="table table-hover">
<thead>
<tr>
<th>Código</th>
<th>Nombre</th>
</tr>
</thead>
</table>
</body>
test.php
```
$sql = "SELECT
req.id as IdArt,
req.item as CodArt,
req.qty_req as Requerido,
req.sales_order as Ov,
concat_ws(' ',stk.itm_name_1,' ',stk.itm_name_2, ' ',stk.itm_name_3) as NombreArt,
ifnull(SUM(iss.quantity),0) as Consumido,
ifnull((select sum(soh.quantity) from mapubli.soh soh where soh.item=req.item),0) as StockActual
FROM
mapubli.so sales
INNER JOIN
mapubli.req req ON sales.num = req.sales_order
INNER JOIN
mapubli.stkitm stk ON stk.itm_code = req.item
LEFT JOIN
mapubli_proy.mpl_web_iss iss ON req.id = iss.req_id
where sales.num = '".$_GET["codov"]."'
group by req.id
order by req.item";
$result = mysqli_query($link, $sql);
if ( !$result ){
die("ERROR");
}else{
while ($data = mysqli_fetch_assoc($result)) {
$arreglo["data"][]=array_map("utf8_encode", $data);
}
echo json_encode($arreglo);
echo "<br>";
echo $_SERVER['REQUEST_URI'];
}
mysqli_free_result($result);
mysqli_close($link);
Replies
Hi @Genjosanzo ,
That looks more like an SQL question, rather than something specific to DataTables. It would be worth asking on StackOverflow or an SQL specific forum.
Cheers,
Colin