【问题标题】:datatables {"error":"An SQL error occurred: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'username' in 'field list'"}datatables {"error":"出现 SQL 错误:SQLSTATE[42S22]: Column not found: 1054 Unknown column 'username' in 'field list'"}
【发布时间】:2014-11-20 12:29:34
【问题描述】:

尝试使用 jQuery、datatable 和 php 从 ajax 调用接收数据。 我收到一条错误消息:

{"error":"出现 SQL 错误:SQLSTATE[42S22]: Column not found: 1054 Unknown column 'username' in 'field list'"}

收到回复时 这是我的 html 和 jquery 代码:

<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
    <th>id</th>
    <th>username</th>
    <th>password</th>
    <th>Position</th>
    <th>mail</th>
</tr>
</thead>

<tfoot>
<tr>
    <th>id</th>
    <th>username</th>
    <th>password</th>
    <th>Position</th>
    <th>mail</th>
</tr>
</tfoot> </table>


    $('#example').dataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": {
            "url": "server.php",
            "dataType": "jsonp"
        }
    } );

这是我的服务器端 php 代码:

    // DB table to use
    $table = 'users';
    // Table's primary key
    $primaryKey = 'id';

    // Array of database columns which should be read and sent back to DataTables.
    // The `db` parameter represents the column name in the database, while the `dt`
    // parameter represents the DataTables column identifier. In this case simple
    // indexes
    $columns = array(
        array( 'db' => 'username', 'dt' => 0 ),
        array( 'db' => 'password',  'dt' => 1 ),
        array( 'db' => 'mail',   'dt' => 2 ),
    );

    $sql_details = array(
        'user' => 'root',
        'pass' => '',
        'db'   => 'autocomplete',
        'host' => 'localhost'
    );


    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
     * If you just want to use the basic configuration for DataTables with PHP
     * server-side, there is no need to edit below this line.
     */
    require( 'ssp.class.php' );

    echo $_GET['callback'].'('.json_encode(
            SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
        ).');';

请有人帮帮我,我是昨天的库存

这是我的表结构

“用户名”列不存在于表中。 – Deepak 31 秒前

我的表中有一个用户名列

【问题讨论】:

  • 你的表(数据库表)结构是什么??
  • “用户名”列不在表中。
  • 我做错了什么?

标签: javascript php jquery datatables jquery-datatables


【解决方案1】:

检查 $sql_details 的数据库名称。

数据库名称是 supercms??

也许你图片的数据库名是对的..

【讨论】:

    猜你喜欢
    • 2016-07-22
    • 2020-12-01
    • 2017-09-02
    • 2011-03-16
    • 1970-01-01
    • 1970-01-01
    • 2019-06-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多