【发布时间】:2015-09-17 11:22:24
【问题描述】:
我最近提出了一个问题,但我的网站仍然遇到问题:
我有一个对 SQL 服务器进行查询的 php,从 html 获取一个 var,但我需要知道是否必须使用某种方法将 var 发送到 php?我的意思是,好的 json,我在文本字段上写了日期,但它没有得到 php 结果。我需要在插入日期后插入一些按钮来调用它,或者它应该是自动插入 var?
这是 php.ini 文件。我将变量放在 WHERE 的最后一个声明中。
<?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_statusevents.shiftindex = hist_eqmtlist.shiftindex AND hist_statusevents.eqmt = hist_eqmtlist.eqmtid AND (hist_eqmtlist.eqmtid='SVEDALA') AND hist_statusevents.category In ('2') 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:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Report Monitor</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/estilos.css">
<script src='js/jquery.js'></script>
<script src='js/bootstrap.js'></script>
</head>
<body>
<header>
<nav class="navbar navbar-inverse navbar-static-top" role="navigation">
</nav>
</header>
<section class="main container">
<div class="row">
<section class="post col-md-12">
<div class="miga-de-pan">
<ol class="breadcrumb">
<li><a href="#">Inicio</a>
</li>
<li><a href="#">Inputs</a>
</li>
<li class="active">Reports</li>
</ol>
</div>
</section>
<section class="post col-md-12">
<input type="text" placeholder="Fecha del Turno" id="shiftdate">
</section>
<div class="row">
<div class="clas col-md-4">
<h4>Indicador 1</h4>
<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>
<ul></ul>
</div>
<div class="clas col-md-4">
<h4>Indicador 2</h4>
<script>
$(document).ready(function() {
$.getJSON('dbquery.php', function(data) {
$.each(data, function(key, val) {
$('ul2').append('<li Reason="' + val.reason + '">' + val.reason + '-' + val.Duracion + '</li>');
});
});
});
</script>
<ul2></ul2>
</div>
<div class="clas col-md-4">
<h4>Indicador 3</h4>
<script>
$(document).ready(function() {
$.getJSON('dbquery.php', function(data) {
$.each(data, function(key, val) {
$('ul3').append('<li Reason="' + val.reason + '">' + val.reason + '-' + val.Duracion + '</li>');
});
});
});
</script>
<ul3></ul3>
</div>
</div>
</div>
</section>
<footer></footer>
</body>
</html>
第一个 json 函数是我尝试插入参数 shifdate 的那个函数。
并且将 shifdate 插入到 section 类中:
<section class="post col-md-12">
<input type="text" placeholder="Fecha del Turno" id="shiftdate">
</section>
另外,php 在 chrome 上给了我这个结果:
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
但如果我排除 $shiftdate = $_GET["shiftdate"]; 以及我将其提供给查询的部分,我没有任何错误。
【问题讨论】:
标签: javascript php json html twitter-bootstrap