繁体   English   中英

第1行请求的未知参数'0'-在第一行未插入任何值

[英]Requested unknown parameter '0' for row 1 - It inserted no value in the first row

这是我的表..数据库中我只有2行数据..但是刷新页面时出现错误,而数据表中有3行数据..第一行没有任何值,因此检索到的数据是3行而不是2行

<table class="table table-striped table-bordered table-hover" id="tbl">
            <thead>
            <tr>
              <th>Delegation Name</th>
              <th>Address(s)</th>
              <th>Contact Number</th>
              <th>Action</th>
            </tr>
            </thead>
            <tbody>
            </tbody>
            <tfoot>
            <tr>
              <th>Delegation Name</th>
              <th>Address(s)</th>
              <th>Contact Number</th>
              <th>Action</th>
            </tr>
            </tfoot>

这是我的JavaScript

    <script type="text/javascript" language="javascript" >
$(document).ready(function () {
    retrieve_user();
});
function retrieve_user(){
  $.ajax({
    url:'conn/callFunc.php',
    method:'POST',
    data:{
      _trans:'retrieve_user'
    },
    success:function(msg){
            var table = $('#tbl').DataTable();
            table.rows.add( $(msg) ).draw();
    }
  })
}
    </script>

这是在我的conn / callfunc.php中

else if($trans === 'retrieve_user'){
    echo $md->retrieve_user();
}

这是我的query.php

public function retrieve_user(){

    $res = null;

    $ret = $this->Connect()->prepare("select id, name, age ,address from tbl_user");
    $ret->execute();
    $ret->bind_result($id,$name,$age,$address);
    while ($ret->fetch()) {

        $res.= "
            <tr>
                <td>$id</td>
                <td>$name</td>
                <td>$age</td>
                <td>$address</td>
            </tr>
        ";
    }
    return $res;    
}

您的问题是由于数组元素为空。 您需要使用array_filter()删除空数组元素,如下所示:

public function retrieve_user(){
    $res = null;
    $ret = $this->Connect()->prepare("select id, name, age ,address from tbl_user");
    $ret->execute();
    $ret->bind_result($id,$name,$age,$address);
    $ret->fetch = array_filter($ret->fetch);
    while ($ret->fetch()) {
    if(!empty($id){
    $res.= "
        <tr>
            <td>$id</td>
            <td>$name</td>
            <td>$age</td>
            <td>$address</td>
        </tr>
    ";
    }
 }
return $res;    
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM