How can I have multiple tables without making a new Editor.php file?

How can I have multiple tables without making a new Editor.php file?

jmack44jmack44 Posts: 5Questions: 2Answers: 0
edited July 2018 in Free community support

I am hoping to have around 10-15 tables setup. Whenever I Add my own data from mysql I get a response saying "could not find 'id' in fieldlist". So to work around this I replace 'id' with the name of my primary key in the 'Editor.php' file. I think its obvious that replicating the file multiple times in a different directory sounds awful. Is there an easy way to do this? Forgive me if this is an extremely nooby question I am just being introduced to jquery as well as this plugin. Surely there is something easy that is flying by my head!

Answers

  • lucaslmlucaslm Posts: 5Questions: 1Answers: 0

    It would help a lot if you could post the contens of Editor.php. Either way, Implementing the back-end is out of datatables' scope.
    Personally, I would place the revelant code on an generic include file (it could be named Editor.php), but instead of fixing on one primary key value, I would assume its value would be in some variable (say $pk) . Later on, for each table I'd need, I would create a file, which would define the variable $pk (and any other needed) and include the generic code. It would then look something like this:

    <?php
      $pk = 'id';
    
      // include file that assumes $pk is set and does all the work;
      include('/path/to/file/Editor.php');
    
  • allanallan Posts: 61,723Questions: 1Answers: 10,108 Site admin

    The Editor.php file is probably the one that comes with the Editor PHP download.

    @jmack44 - If you want one shared file for all tables, I'd suggest something like this:

    <?php
    
    include( "../../php/DataTables.php" );
    use ...;
    
    if ( $_GET['table'] === 'staff' ) {
      Editor::inst( $db, 'staff' )
        ->fields( ... )
        ...
    }
    else if ( $_GET['table'] === 'customers' ) {
      Editor::inst( $db, 'customers' )
        ->fields( ... )
        ...
    }
    ...
    

    Then for your DataTables and Editor ajax urls add ?table=staff or ?table=customers.

    Allan

This discussion has been closed.