0

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Sorry, i need to execute the query on the php and show the results on my html page, but I need to insert some parameters on the query, and this paraemters must be inserted by the client in this case, te date for the query.
at this moment if I leave the php withou insert the var shifdate i works perfectly, but i need to inser shifdate as a variable of the query
Ok, so this should do the trick var shiftdate = $('#shiftdate').val(); $.getJSON('dbquery_plus_shiftdate.php',{shiftdate: shiftdate} ... previously you was just passing string "shiftdate" to php function.
Thath part should be on the HTML? the php must remain as is?
I leave it like this: <script> $(document) .ready (function(){ shiftdate = $('#shiftdate').val() $.getJSON('dbquery_plus_shiftdate.php',{shiftdate: shiftdate}, function(data) { $.each(data, function(key,val){ $('ul').append('<li Reason="'+val.reason+'">'+val.reason+'-'+val.Duracion+'</li>'); }); }); }); </script>
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.