{"error":"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'field
{"error":"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'field
i'm just a bginner at using datatables i'm just following the instruction until a this error came can anyone help me
{"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
help
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 notid
(the default):Allan
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..
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
//this is the html:
//this is the javascript
//for the changes in my php
thats my whole code sir tell me what i must do thank you
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
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>
<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' } ] } ); } );i already fixed it thnx
Hi chrizer,
How did you fix this ?
Thanks!