使用 getJson 在 php 查询中插入变量日期

insert variable date on php query with getJson

我在 PHP 上得到了这个查询,它必须根据不同的值进行更改。

我需要在我的 html 页面上输入这些变量,我将其中一个值命名为 shiftdate,但可能我必须通过 json 在查询中输入更多变量。

问题是我的查询没有读取 var

我现在有这个权利

<?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);

我想进入查询的值在这个 html 部分:

                <section class="post col-md-12">
                <input type="text" placeholder="Date on dd-mm-yy" id="shiftdate">

                </section>

通过了这个 json(没有 ,{shiftdate: "shiftdate"},它工作得很好)但是如果我添加它,它就不起作用:

$(文档).ready(函数(){ $.getJSON('dbquery_plus_shiftdate.php',{shiftdate: "shiftdate"}, 函数(数据) { $.each(数据,函数(键,值){ $('ul').append(''+val.reason+'-'+val.Duracion+''); }); }); });

在另一边,

$shiftdate = $_GET["shiftdate"]; //我需要在查询中输入的变量之一

php 页面给我这个错误:

注意:未定义索引:C:\xampp\htdocs\byp1\dbquery_plus_shiftdate.php 第 5 行

中的 shiftdate

警告:odbc_exec():SQL 错误:[Microsoft][SQL Server Native Client 10.0][SQL Server]正在执行 SQL直接地;没有光标。,SQL 在 C:\xampp\htdocs\byp1\dbquery_plus_shiftdate.php 的 SQLExecDirect 中状态 01000 第 12

你想达到什么目的,因为我不明白你的问题。 您想要使用查询中的数据填充 html,或者想要通过输入的数据获得 Json。