Join tables - working with multiple SQL tables
Join tables - working with multiple SQL tables
![kringel](https://secure.gravatar.com/avatar/5695af6b4398fbbc3e8c44eeba515666/?default=https%3A%2F%2Fvanillicon.com%2F5695af6b4398fbbc3e8c44eeba515666_200.png&rating=g&size=120)
Hello.
I'm trying to implement this https://editor.datatables.net/examples/simple/join.html
My code
Javascript
(function($){
$(document).ready(function() {
var editor = new $.fn.dataTable.Editor( {
ajax: 'php/table.users.php',
table: '#users',
fields: [
{
"label": "\u0411\u0440\u0435\u043d\u0434:",
"name": "brand"
},
{
"label": "WEB:",
"name": "web",
"attr": {
"placeholder": "http://example.com"
}
},
{
"label": "\u0412\u0438\u0434 \u0434\u0435\u044f\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438:",
"name": "activity",
"type": "select",
placeholder: "Select an option"
}
],
} );
var table = $('#users').DataTable( {
ajax: 'php/table.users.php',
"columnDefs": [ {
"targets": 2,
"data": "download_link",
"render": function ( data, type, row, meta ) {
if(row['web'] != null) {
return type === "display" ?
'<a href="' + data + '" target="_blank">' + data + '</a>' : data;
return type === "filter" ?
data : data;
} else {
return data;
}
}
}],
columns: [
{
"data": "brand"
},
{
"data": "web"
},
{
"data": "options.activity"
}
],
select: true,
scrollX: true,
autoWidth: true,
stateSave: true,
dom: "<'ui stackable grid'"+
"<'row'"+
"<'nine wide column'Q>"+
">"+
"<'row'"+
"<'eight wide column'B>"+
"<'right aligned eight wide column'f>"+
">"+
"<'row dt-table'"+
"<'sixteen wide column'tr>"+
">"+
"<'row'"+
"<'seven wide column'l>"+"<'two wide column'i>"+
"<'right aligned seven wide column'p>"+
">"+
">",
buttons: [
{ extend: "create", editor: editor },
{ extend: "edit", editor: editor },
{ extend: "remove", editor: editor },
{ extend: 'colvis',
text: 'Hide columns'},
{
extend: 'excel',
text: 'Save page in Excel',
exportOptions: {
modifier: {
page: 'current'
}
}
}
]
} );
}(jQuery));
Server script
<?php
/*
* Editor server script for DB table users
* Created by http://editor.datatables.net/generator
*/
// DataTables PHP library and database connection
include( "lib/DataTables.php" );
// Alias Editor classes so they are easy to use
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate,
DataTables\Editor\ValidateOptions;
// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'users', 'id' )
->fields(
Field::inst( 'users.brand' )
->validator( Validate::notEmpty() ),
Field::inst( 'users.web' )
->setFormatter( Format::ifEmpty(null) ),
Field::inst( 'users.activity' )
->options( Options::inst()
->table( 'options' )
->value( 'id' )
->label( 'selectable' )
)
->validator( Validate::dbValues() ),
Field::inst( 'users.subactivity' )
->setFormatter( Format::ifEmpty( null ) )
->validator( Validate::notEmpty() ),
Field::inst( 'options.selectable' )
)
->leftJoin( 'options', 'options.id', '=', 'users.activity' )
->process( $_POST )
->json();
My options table
My users table
I got this error on page reload
What am I doing wrong? Thanks in advance
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You've got this:
I think it should be:
note
field
(not fields) and the removal ofid
,Colin
Thanks. That helped