【发布时间】:2015-06-30 13:16:41
【问题描述】:
我在 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"},它工作得很好)但是如果我添加它,它就不起作用:
$(document) .ready (function(){ $.getJSON('dbquery_plus_shiftdate.php',{shiftdate: "shiftdate"}, function(data) { $.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;没有光标。,第 12 行 C:\xampp\htdocs\byp1\dbquery_plus_shiftdate.php 中 SQLExecDirect 中的 SQL 状态 01000
【问题讨论】:
标签: javascript php jquery json getjson