I got this query made on PHP that must change accordding different values.
I need to input these variables on my html page, i named one of this values as shiftdate, but probably I will have to put more variables via json on the query.
the problem is that my query doesn´t read the var
i Have this right Now
<?php
function getArraySQL(){
$dsn = "prueba";
$connect = odbc_connect( $dsn, '', '' );
$shiftdate = $_GET["shiftdate"]; //one of the variables that i need to input on my query
$query = " SELECT hist_statusevents.reason, Sum(hist_statusevents.duration/3600) AS 'Duracion'
FROM hist_statusevents, hist_eqmtlist, hist_exproot
WHERE hist_exproot.shiftindex = hist_statusevents.shiftindex AND hist_exproot.ddmmyy =$shiftdate
GROUP BY hist_statusevents.reason
ORDER BY Duracion DESC";
if(!$rs = odbc_exec($connect, $query)) die();
$rawdata = array();
$i=0;
while($row = odbc_fetch_array($rs))
{
$rawdata[$i] = $row;
$i++;
}
odbc_close( $connect );
return $rawdata;
}
$myarray = getArraySQL();
echo json_encode($myarray);
the value that i want to get into the query is in this html section:
<section class="post col-md-12">
<input type="text" placeholder="Date on dd-mm-yy" id="shiftdate">
</section>
Passed trough this json (whitout the ,{shiftdate: "shiftdate"},it works perfectly) but if I add it, it doesnt work :
$(document) .ready (function(){ $.getJSON('dbquery_plus_shiftdate.php',{shiftdate: "shiftdate"}, function(data) { $.each(data, function(key,val){ $('ul').append(''+val.reason+'-'+val.Duracion+''); }); }); });on the other side, with the
$shiftdate = $_GET["shiftdate"]; //one of the variables that i need to input on my query
the php page give me this error:
Notice: Undefined index: shiftdate in C:\xampp\htdocs\byp1\dbquery_plus_shiftdate.php on line 5
Warning: odbc_exec(): SQL error: [Microsoft][SQL Server Native Client 10.0][SQL Server]Executing SQL directly; no cursor., SQL state 01000 in SQLExecDirect in C:\xampp\htdocs\byp1\dbquery_plus_shiftdate.php on line 12
What do you want to achieve becouse i don't understand your question. You want to populate your html with data from query, or want to get Json by data you puted into inputs.