{"error":"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'field

{"error":"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'field

chriszerchriszer Posts: 7Questions: 1Answers: 0
edited October 2016 in Free community support

i'm just a bginner at using datatables i'm just following the instruction until a this error came can anyone help me :neutral:

{"error":"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'field

this is the code:

include( "../php/DataTables.php" );

use DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Join,
DataTables\Editor\Upload,
DataTables\Editor\Validate;

$editor = Editor::inst( $db, 'holder_table')
->fields(
Field::inst( 'firstname' ),
Field::inst( 'middlename' ),
Field::inst( 'lastname' ),
Field::inst( 'extension' )
)
->process( $_POST )
->json();

this is just my simple code and following instruction until i get the error help would be appreciated

This question has an accepted answers - jump to answer

Answers

  • chriszerchriszer Posts: 7Questions: 1Answers: 0

    help :(

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin

    Hi,

    What is your table's primary key column name? That will need to be defined in the optional third parameter to the Editor constructor if it is not id (the default):

    $editor = Editor::inst( $db, 'holder_table', 'myId')
    

    Allan

  • chriszerchriszer Posts: 7Questions: 1Answers: 0
    edited October 2016

    yes sir i just added an id and now this is the output on the screenshot and nothing yet appears to my table and i attached also my javascript error on the second screentshot ... this is the table i'm trying to imitate with edit end delete buttons and functionality also. https://editor.datatables.net/examples/simple/inTableControls.html and i got another error ..

    i send my errors in the screenshot and the output of my php..

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin

    That error suggests that the columns option doesn't contain exactly four columns. Could you show me your HTML and Javascript as well please?

    Thanks,
    Allan

  • chriszerchriszer Posts: 7Questions: 1Answers: 0
    edited October 2016

    //this is the html:

    <html>
        
        <head>
        
    
        <link rel="stylesheet" href="css/dataTables.min.css">
        
        <script src="js/jquery.js"></script>
       
        <script src="js/jquery.dataTables.min.js"></script>
        <script src="js/dataTables.editor.min.js"></script>
        </head>
    
    <body>
        <table id="example" class="display" cellspacing="0" width="100%">
            <thead>
                <tr>
                    <th>Firstname</th>
                    <th>Middlename</th>
                    <th>Lastname</th>
                    <th>Extension</th>
             
            </thead>
            <tfoot>
                <tr>
                   <th>Firstname</th>
                    <th>Middlename</th>
                    <th>Lastname</th>
                    <th>Extension</th>
                </tr>
            </tfoot>
        </table>
        
        
        
    </body>
        
    </html>
    

    //this is the javascript

    <script>
        var editor; // use a global for the submit and return data rendering in the examples
     
    $(document).ready(function() {
        editor = new $.fn.dataTable.Editor( {
            "ajax": "../php/staff.php",
            "table": "#example",
            "fields": [ {
                    "label": "Firstname:",
                    "name": "firstname"
                }, {
                    "label": "Middlename:",
                    "name": "middlename"
                }, {
                    "label": "Lastname:",
                    "name": "lastname"
                }, {
                    "label": "Extension:",
                    "name": "extension"
                }
            ]
        } );
     
        // New record
        $('a.editor_create').on('click', function (e) {
            e.preventDefault();
     
            editor.create( {
                title: 'Create new record',
                buttons: 'Add'
            } );
        } );
     
        // Edit record
        $('#example').on('click', 'a.editor_edit', function (e) {
            e.preventDefault();
     
            editor.edit( $(this).closest('tr'), {
                title: 'Edit record',
                buttons: 'Update'
            } );
        } );
     
        // Delete a record
        $('#example').on('click', 'a.editor_remove', function (e) {
            e.preventDefault();
     
            editor.remove( $(this).closest('tr'), {
                title: 'Delete record',
                message: 'Are you sure you wish to remove this record?',
                buttons: 'Delete'
            } );
        } );
     
        $('#example').DataTable( {
            ajax: "../php/staff.php",
            columns: [
                { data: null, render: function ( data, type, row ) {
                    // Combine the first and last names into a single table field
                    return data.firstname+' '+data.lastname;
                } },
                { data: "firstname" },
                { data: "middlename" },
                { data: "lastname" },
                { data: "extension" },
                {
                    data: null,
                    className: "center",
                    defaultContent: '<a href="" class="editor_edit">Edit</a> / <a href="" class="editor_remove">Delete</a>'
                }
            ]
        } );
    } );
    </script>
    

    //for the changes in my php

    include( "../php/DataTables.php" );
    
    use  DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Join,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate;
        
        
    $editor = Editor::inst( $db, 'holder_table','person_id')
             ->fields(
            Field::inst( 'person_id' ),
            Field::inst( 'firstname' ),
            Field::inst( 'middlename' ),
            Field::inst( 'lastname' ),
            Field::inst( 'extension' )
        )
           ->process( $_POST )
           ->json();
    
  • chriszerchriszer Posts: 7Questions: 1Answers: 0
    edited October 2016

    thats my whole code sir tell me what i must do thank you

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin
    Answer ✓

    Your Javascript defines 6 columns in the columns array. But the HTML only has 4 columns, hence the error message. The two should match.

    Allan

  • chriszerchriszer Posts: 7Questions: 1Answers: 0
    edited October 2016

    both are now equal and now this is the what occurs :(

    this are some of the changes iv'e made in html and javascript as u said bout those fields and i recieve a new error on the screenshot i knew my url is right but what went wrong?
    **.

    //html 4 fields

    <html>

    <head>
    
    
    <link rel="stylesheet" href="css/dataTables.min.css">
    
    <script src="js/jquery.js"></script>
    
    <script src="js/jquery.dataTables.min.js"></script>
    <script src="js/dataTables.editor.min.js"></script>
    </head>
    

    <body>
    <table id="example" class="display" cellspacing="0" width="100%">
    <thead>
    <tr>
    <th>Name</th>
    <th>Middlename</th>
    <th>Extension</th>
    <th>Edit / Delete</th>
    </thead>
    <tfoot>
    <tr>
    <th>Name</th>
    <th>Middlename</th>
    <th>Extension</th>
    <th>Edit / Delete</th>
    </tr>
    </tfoot>
    </table>

    </body>

    </html>

    javascricpt// 4 fields

    var editor; // use a global for the submit and return data rendering in the examples $(document).ready(function() { editor = new $.fn.dataTable.Editor( { "ajax": "../php/staff.php", "table": "#example", "fields": [ { "label": "Firstname:", "name": "firstname" }, { "label": "Middlename:", "name": "middlename" }, { "label": "Lastname:", "name": "lastname" }, { "label": "Extension:", "name": "extension" } ] } ); // New record $('a.editor_create').on('click', function (e) { e.preventDefault(); editor.create( { title: 'Create new record', buttons: 'Add' } ); } ); // Edit record $('#example').on('click', 'a.editor_edit', function (e) { e.preventDefault(); editor.edit( $(this).closest('tr'), { title: 'Edit record', buttons: 'Update' } ); } ); // Delete a record $('#example').on('click', 'a.editor_remove', function (e) { e.preventDefault(); editor.remove( $(this).closest('tr'), { title: 'Delete record', message: 'Are you sure you wish to remove this record?', buttons: 'Delete' } ); } ); $('#example').DataTable( { ajax: "php/staff.php", columns: [ { data: null, render: function ( data, type, row ) { // Combine the first and last names into a single table field return data.firstname+' '+data.lastname; } }, { data: "middlename" }, { data: "extension" }, { data: null, className: "center", defaultContent: 'Edit / Delete' } ] } ); } );
  • chriszerchriszer Posts: 7Questions: 1Answers: 0

    i already fixed it thnx

  • map@odenterprise.orgmap@odenterprise.org Posts: 14Questions: 4Answers: 0

    Hi chrizer,

    How did you fix this ?

    Thanks!

This discussion has been closed.