Error joining two mysql tables.

Error joining two mysql tables.

dt_userdt_user Posts: 51Questions: 16Answers: 0
edited June 2019 in Free community support

Good night,
I am trying to join the tables baptask_sheet and people. They are both in the same database called Tasks.
Code Explanation: I have clickable tabs that displays a persons name. When it is clicked all data pertaining to that individual is loaded into datatable. When I use editor edit api it works perfectly BUT when i try to create a new record I get an error saying the foreign key needs data.(This is because I do not have the persons name being sent back to the database).
Solution: To fix this error i created a hidden column that concats the first and last name. I use editor presubmit function to send the name to the database along with the visible fields and form_options submit:'all'.
My server.php file has the joining in editor.
Error message: DataTables warning: table id=task_table - Requested unknown parameter 'baptask_sheet.StartTD' for row 0, column 2. For more information about this error, please see http://datatables.net/tn/4
(alerted message when I load datatable).

js
var table = $('#task_table').DataTable({
          data:jsonData,
          rowId: "sch_id",
          columns: [
            {
              className: 'details-control',
              orderable: false,
              data: null,
              defaultContent: ''
            },
            {
              data: null, render:function (data, type, row) {
                return data.fname+' '+data.lname;
              }
            },
            {data: "baptask_sheet.StartTD"},
            {data: "baptask_sheet.EndTD"},
            {data: "baptask_sheet.TaskName"},
            {data: "baptask_sheet.Status"},
            {data: "baptask_sheet.HoursWorked"},
            {
              data: null,
              className: "dt-body-center",
              defaultContent: '<a href="" class="editor_edit">Edit</a>'  /* '<i class="fa fa-pencil-square"></i>'*/
            }
          ],
          "columnDefs": [
            {
                "targets": [ 1 ],
                //"visible": false,
                "searchable": false
            }
        ],
          order: [[1,'asc']],
          select: true
        });

        /*editor begin*/
        editor = new $.fn.dataTable.Editor( {
        "ajax": "controller/server.php",
        "table": "#task_table",
        "idSrc": "sch_id",
       "fields": [ {

               "label": "Start Time/Date:",
               "name": "baptask_sheet.StartTD"
           }, {
              "label": "End Time/Date:",
              "name": "baptask_sheet.EndTD"
           }, {
              "label": "Task Name:",
              "name": "baptask_sheet.TaskName"
           },

           {
              "type": "select",
              "label": "Status:",
              "name": "baptask_sheet.Status",
              "options": [
                 {"label": "Select a Status", "value": ''},
                 {"label": "In-Progress", "value": 'In-progress'},
                 {"label": "Completed", "value": 'Completed'}
              ]
           },


            {
              "label": "Hours Worked:",
              "name": "baptask_sheet.HoursWorked"
             }
       ],
       "formOptions": {
            "main": {
              "submit": 'all'
            }
        }

   } );//edit_end

   // editor.on('preSubmit', function (e, d, type) {
   //   if( type === 'create'){
   //     d.data.fname+' '+d.data.lname;
   //   }
   // });
server.php
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, 'baptask_sheet')
    ->field(
        Field::inst( 'baptask_sheet.StartTD' ) //gives the error
            ->validator( Validate::notEmpty( ValidateOptions::inst()
                ->message( 'required' )
            ) ),
        Field::inst( 'baptask_sheet.EndTD' )
            ->validator( Validate::notEmpty( ValidateOptions::inst()
                ->message( 'required' )
            ) ),
        Field::inst( 'baptask_sheet.TaskName' ),
        Field::inst( 'baptask_sheet.Status' )
            ->validator( Validate::notEmpty( ValidateOptions::inst()
                ->message( 'required' )
            ) ),
        Field::inst( 'baptask_sheet.HoursWorked' )
    )
        ->leftJoin('people', 'p_id', '=', 'baptask_sheet.p_id')
    ->process($_POST)
    ->json();

Please let me know what I am doing wrong.
Thank you.

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    One big problem here, is that you're posting multiple threads at the same time, so it's hard to understand what you're current issue. There were three from you this morning. If you are experiencing problems still, can we consolidate on your thread here.

    Cheers,

    Colin

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    Can you show me what jsonData contains please? Even better would be a link to the page showing the issue so I can debug it directly.

    Allan

  • dt_userdt_user Posts: 51Questions: 16Answers: 0

    how do i show you a link to the page?

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    Ideally just copy / paste the URL into here. But I'm guessing you might be using a local host based on your reply?

    If that's the case please can you use the debugger to give me a trace - click the Upload button and then let me know what the debug code is.

    Allan

This discussion has been closed.