【发布时间】:2014-10-13 15:28:33
【问题描述】:
我是 Satya,试图从数据库中获取数据并在 Jquery 数据表中显示数据。
我在下面包含了我的代码。这里的场景是我试图在没有任何 where 子句的情况下获取 sql 查询数据。我能够在数据表中显示数据,当我包含它显示的 where 子句时:Cannot read property error of null,我尝试了很多来解决这个问题,即使我通过 ajax 将数据从 php 获取到 javascript 页面,但它没有将数据获取到数据表,这是我的代码:
jquery:
$("<table id='example' class='display' cellspacing='0' width='100%' style:'text-align:center;'>"
+"<thead>"
+"<tr>"
+"<th>EID</th>"
+"<th>EMICH_EMAIL</th>"
+"<th>FIRSTNAME</th>"
+"<th>LASTNAME</th>"
+"<th>SIGN_IN</th>"
+"<th>SIGN_OUT</th>"
+"<th>DURATION</th>"
+"</tr>"
+"</thead>"
+"<tbody>").appendTo('#table-section');
$('#example').dataTable({
"dom": 'T<"clear">lfrtip',
"tableTools": {
"sSwfPath":"http://cdn.datatables.net/tabletools/2.2.2/swf/copy_csv_xls_pdf.swf"
},
"bProcessing": false,
"sAjaxDataProp":'',
"sAjaxSource":"fetchdata.php"
});
PHP:
<?php
include 'dataconnection.php';
$user_id=$_POST['eid'];
$from=$_POST['startdate'];
$to=$_POST['enddate'];
$students_data="select st.EID,st.emich_email,firstname,lastname,sign_in,sign_out, " +
"SEC_TO_TIME(TIME_TO_SEC(timediff(sign_out,sign_in))) AS totalduration from "+
"student_details st INNER JOIN scans sc ON st.emich_email = sc.emich_email where st.EID ='$user_id'";
$students_data_query=mysqli_query($connection,$students_data);
if($students_data_query){
while($row = mysqli_fetch_array($students_data_query)){
$output[]=array($row[0],$row[1],$row[2],$row[3],$row[4],$row[5],$row[6]);
}
echo json_encode($output);
//echo $user_id;
}else
echo die("The error is:".mysqli_error($connection));
?>
【问题讨论】:
-
需要对NULL值进行处理。在您的查询中,输入
IFNULL()函数。 -
您好 Fernando 我的数据中没有任何 NUll 值,即使从数据库中获取数据后,我只是在屏幕上提醒它们,我没有找到任何空值,但数据没有得到显示在数据表中。非常感谢您抽出时间来回答我的问题。
-
嗯...我明白了.. JSON 输出的格式是什么?
-
您好费尔南多,我正在通过以下方式获得,[["银行存款","12345.4567","3456.90","3456.435"],["旅行","98712.67","2458.90 ","3981.25"]],这里每块值都是数据表中的单行
标签: php ajax datatables jquery-datatables