【问题标题】:insert variable date on php query with getJson使用getJson在php查询中插入可变日期
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

    • 对不起,我需要在php上执行查询并在我的html页面上显示结果,但是我需要在查询中插入一些参数,这个参数必须由客户端插入案例,查询日期。
    • 此时如果我离开 php 而不插入 var shifdate 我工作得很好,但我需要插入 shifdate 作为查询的变量
    • 好的,所以这应该可以解决问题 var shiftdate = $('#shiftdate').val(); $.getJSON('dbquery_plus_shiftdate.php',{shiftdate: shiftdate} ...以前您只是将字符串“shiftdate”传递给php函数。
    • 那部分应该在 HTML 上? php 必须保持原样?
    • 我这样写:
    猜你喜欢
    • 2015-09-17
    • 2019-12-01
    • 2015-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-17
    • 2014-02-12
    • 1970-01-01
    相关资源
    最近更新 更多