gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 09:42:39 24 4
gpt4 key购买 nike

我在 PHP 上进行了此查询,该查询必须根据不同的值进行更改。

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

问题是我的查询没有读取变量

我现在就有这个

<?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(数据, 函数(key,val){ $('ul').append(''+val.reason+'-'+val.Duraciion+''); }); }); });

在另一边,与

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

php 页面给我这个错误:

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

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

最佳答案

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

关于javascript - 使用 getJson 在 php 查询中插入变量日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31139333/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com