mySQL join
mySQL join
nskwortsow
Posts: 120Questions: 0Answers: 0
Hi,
I am following the tutorial to the letter, but in my own implementation,
1) My SELECT box is empty (edit/new)
2) I get a JS error:
Undefined is not an object (line 1617(
>>> var fieldType = Editor.fieldTypes[ fieldConf.type ];
#
The PHP code which I use
# Table layout
tblExerciseEquipment
EEquipmentID
EquipmentName
f_LanguageID
tblLanguages
> LanguageID
> LName
# PHP code
Editor::inst( $db, 'tblExerciseEquipment' )
->fields(
Field::inst( 'EquipmentName' )->validator( 'Validate::required' ),
Field::inst( 'f_LanguageID' )->validator( 'Validate::required' )
)
->join(
Join::inst('tblLanguages','object')
->join('f_LanguageID','LanguageID')
->fields(
//Field::inst( 'LanguageID' )->validator( 'Validate::required' ),
Field::inst( 'LName' ))
)
->pkey('EEquipmentID')
->process( $_POST )
->json();
# JS
editor = new $.fn.dataTable.Editor( {
"ajaxUrl": "ajax_content_exerciseEquipment.php",
"domTable": "#tblExerciseEquipment",
"fields": [ {
"label": "Language:",
// The 'id' value from the property is used to set the value
// of the select list.
"name": "tblLanguages.LanguageID",
"type": "select"
},
{
"label": "Equipment name:",
"name": "EquipmentName"
}
]
} );
$('#tblExerciseEquipment').dataTable( {
"sDom": "Tfrtip",
"sAjaxSource": "ajax_content_exerciseEquipment.php",
"aoColumns": [
{
// Use the 'name' property from the 'dept' object in the
// JSON. It might not be set, so we also provide a default.
"mData": "tblLanguages.LName",
"sDefaultContent": ""
},
{ "mData": "EquipmentName" }
],
"oTableTools": {
"sRowSelect": "multi",
"aButtons": [
{ "sExtends": "editor_create", "editor": editor },
{ "sExtends": "editor_edit", "editor": editor },
{ "sExtends": "editor_remove", "editor": editor }
]
},
"fnInitComplete": function ( settings, json ) {
// Set the allowed values for the select and radio fields based on
// what is available in the database
editor.field('dept.id').update( json.dept );
editor.field('access[].id').update( json.access );
}
} );
I am following the tutorial to the letter, but in my own implementation,
1) My SELECT box is empty (edit/new)
2) I get a JS error:
Undefined is not an object (line 1617(
>>> var fieldType = Editor.fieldTypes[ fieldConf.type ];
#
The PHP code which I use
# Table layout
tblExerciseEquipment
EEquipmentID
EquipmentName
f_LanguageID
tblLanguages
> LanguageID
> LName
# PHP code
Editor::inst( $db, 'tblExerciseEquipment' )
->fields(
Field::inst( 'EquipmentName' )->validator( 'Validate::required' ),
Field::inst( 'f_LanguageID' )->validator( 'Validate::required' )
)
->join(
Join::inst('tblLanguages','object')
->join('f_LanguageID','LanguageID')
->fields(
//Field::inst( 'LanguageID' )->validator( 'Validate::required' ),
Field::inst( 'LName' ))
)
->pkey('EEquipmentID')
->process( $_POST )
->json();
# JS
editor = new $.fn.dataTable.Editor( {
"ajaxUrl": "ajax_content_exerciseEquipment.php",
"domTable": "#tblExerciseEquipment",
"fields": [ {
"label": "Language:",
// The 'id' value from the property is used to set the value
// of the select list.
"name": "tblLanguages.LanguageID",
"type": "select"
},
{
"label": "Equipment name:",
"name": "EquipmentName"
}
]
} );
$('#tblExerciseEquipment').dataTable( {
"sDom": "Tfrtip",
"sAjaxSource": "ajax_content_exerciseEquipment.php",
"aoColumns": [
{
// Use the 'name' property from the 'dept' object in the
// JSON. It might not be set, so we also provide a default.
"mData": "tblLanguages.LName",
"sDefaultContent": ""
},
{ "mData": "EquipmentName" }
],
"oTableTools": {
"sRowSelect": "multi",
"aButtons": [
{ "sExtends": "editor_create", "editor": editor },
{ "sExtends": "editor_edit", "editor": editor },
{ "sExtends": "editor_remove", "editor": editor }
]
},
"fnInitComplete": function ( settings, json ) {
// Set the allowed values for the select and radio fields based on
// what is available in the database
editor.field('dept.id').update( json.dept );
editor.field('access[].id').update( json.access );
}
} );
This discussion has been closed.
Replies
1) the tblExerciseEquipment is empty at the moment
2) It's an inner join (e.g. SELECT EquipmentName,LName FROM tblExerciseEquipment,tblLanguages WHERE LanguageID = f_LanguageID)
###
Notice: Undefined index: access in /Users/nathan/Sites/Physitrack.com/functions/datatables/Editor/Join.php on line 474
{"id":"row_29","error":"","fieldErrors":[],"data":[],"row":{"DT_RowId":"row_29","first_name":"cHamilton","last_name":"Blackburn","dept":{"id":"3","name":"Pre-Sales"},"access":[],"extra":{"comments":"","review":""}}}
http://editor.datatables.net/release/DataTables/extras/Editor/examples/join.html
I have just released Editor 1.2.2 and it has number of bug fixes in it. I'd suggest updating to the new release and see if that addresses the issue for you. If not, can you link us to your page please?
Allan