【问题标题】:How to retrieve data from database using Ajax and OOP php如何使用 Ajax 和 OOP php 从数据库中检索数据
【发布时间】:2017-12-05 06:21:31
【问题描述】:

我打算用 ajax 和 php 开发网页。但我的 get_data_in_table 函数有问题。它将以表结构显示数据。但是当我运行此代码时它显示错误。其他人工作正常。它在while循环中显示错误。但我找不到任何问题。

    class get_data()

    {
     public function get_data_in_table($query){
            $output='';
            $result=  $this->Getdata($query);
            $output.='
                    <table class="table table-bordered table-striped">
                    <tr>
                    <th>Countty</th>
                    <th>Airline Name</th>
                    <th>Arrival Time</th>
                    <th>Status</th>
                    <th>Comment</th>


    </tr>';
            while($row= mysqli_fetch_array($result)){
                $output .='

                        <tr>
    <td>'.$row->country.'</td>
    <td>'.$row->air_line.'</td>
        <td>'.$row->arrival_time.'</td>
          <td>'.$row->status.'</td>
              <td>'.$row->comment.'</td>


    </tr>';


            }
            $output.='</table>';
            return $output;
                    }
?>

【问题讨论】:

  • okaaay,它显示什么错误?
  • 您分享的代码没有任何?&gt;
  • 请同时提供您的 ajax 代码。您能否突出显示第 行号。 56
  • 类的右大括号不在您共享的代码中。您关闭了函数体,但类体仍处于打开状态。
  • 类中缺少右括号

标签: php jquery ajax oop


【解决方案1】:

我猜我找到了:

  class get_data()

    {
     public function get_data_in_table($query){
            $output='';
            $result=  $this->Getdata($query);
            $output.='
                    <table class="table table-bordered table-striped">
                    <tr>
                    <th>Countty</th>
                    <th>Airline Name</th>
                    <th>Arrival Time</th>
                    <th>Status</th>
                    <th>Comment</th>


    </tr>';
            while($row= mysqli_fetch_array($result)){
                $output .='

                        <tr>
    <td>'.$row->country.'</td>
    <td>'.$row->air_line.'</td>
        <td>'.$row->arrival_time.'</td>
          <td>'.$row->status.'</td>
              <td>'.$row->comment.'</td>


    </tr>';


            }
            $output.='</table>';
            return $output;
                    }
} // This was missing
    ?>

【讨论】:

  • 是的。这是个问题
  • 那太好了!玩得开心
猜你喜欢
  • 1970-01-01
  • 2012-02-21
  • 1970-01-01
  • 1970-01-01
  • 2015-09-05
  • 2016-08-16
  • 1970-01-01
  • 1970-01-01
  • 2017-04-18
相关资源
最近更新 更多