Okay
  Public Ticket #1154065
MySql Query based table
Closed

Comments

  • Nadeem started the conversation

    I want my new wptable to be able to load a single row from a MySQL table that I had added.  When I use a query without a WHERE clause, the wptable saves correctly and I am able to preview the rows - see attachment wptable_issue_sc1.jpg.  

    But when i added a WHERE clause to the table the Save operation looks like it fails, since the page reloads with just a date-time shown at the top of the page and nothing else at all - see attachment wptable_issue_sc2.jpg.  

    Here is the definition of the table (CREATE as well as INSERT statements).  

    CREATE TABLE `my_test_table` (
      `from_date` date NOT NULL,
      `breakfast` varchar(10) DEFAULT NULL,
      `lunch` varchar(10) DEFAULT NULL,
      `dinner` varchar(10) DEFAULT NULL
      PRIMARY KEY (`from_date`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    INSERT INTO my_test_table (from_date, breakfast, lunch, dinner) VALUES 
    ('2017-01-01', '6:00 AM', '11:30 AM', '6:15 PM'),
    ('2017-02-01', '7:40 AM', '12:00 PM', '7:00 PM'),
    ('2017-03-01', '8:15 AM', '12:30 PM', '7:30 PM'),
    ('2017-04-01', '8:35 AM', '12:45 PM', '7:45 PM'),
    ('2017-05-01', '8:45 AM', '1:00 PM', '8:00 PM'),
    ('2017-06-01', '9:00 AM', '1:30 PM', '8:30 PM')

    The SELECT query that fails as shown in the wp table definition above runs correctly and returns the correct row within phpMyAdmin.

    SELECT *
    FROM my_test_table
    WHERE from_date = (
    SELECT max( from_date )
    FROM my_test_table
    WHERE from_date <= curdate( ) )

    How do I get the wptable to pick up the single row that my query is designed to return.  If this does not work than I have no need for this plugin and will request that I be able to get a refund of the purchase price.

    Thank you!



  • [deleted] replied

    Hi Nadeem,
    Thank you for the purchase.

    When you add that query in wpDataTables plugin what kind of issue do you have? There is more then one record in the table?

    Because you are using functions like MAX and CURDATE I suggest you to create MySQL View from your query and then use that MySQL View as wpDataTable input. To see how to create MySQL View please take a look at this link.

    After that you should create wpDataTable like:

    SELECT * FROM view_name
  • Nadeem replied

    Thank you for the suggestion Milos.  I can create a view, but the problem seems to be that the plugin is not able to work with ANY WHERE clauses in the query at all.  I know that my example used some relatively complicated functions in the WHERE clause, but if I change the query to an extremely simply WHERE clause as shown below, the same problem still persists.

    select * from wp_posts where post_author=1

    This query could not be any simpler but as soon as I try to save a wpDataTable item with this query, the page that results is what I showed in my  "wptable_issue_sc2.jpg" screen shot.

    I tried the same query in the sandbox version that is available from http://sandbox.wpdatatables.com/ and that works just fine.  There must be something wrong with the version that I have installed - which is version 1.7.2.  

    What version is installed on the Sandbox?

  • Nadeem replied

    Figured out that the firewall on the site was blocking the ajax module that was making the query request to the database.  So the issue is not related to  the WHERE clause.  However, the SQL query is taking a LOOOONG time to bring back a dozen or so rows back from the database.  The same query when run in the phpMyAdmin tool comes back in a few seconds.  Why are the results taking so long through the plugin?  Are there some configurations that need to be tweaked to make the queries run faster?

    Thanks.

  • Nadeem replied

    Please go ahead and close the ticket.  The query is now returning in a reasonable amount of time.  Thank you.

  • Nadeem replied

    Actually one more question about this table that is now coming up in the GUI.  The query returns a single row by design.  It will ALWAYS return a single row.  I do not want to show the SEARCH box and the text below the table (Showing x of y entries) - please refer to the attached screen shot "wtable_issue_sc4.jpg".  How do I hide these two things?

  • [deleted] replied

    Hi Nadeem,

    You can take a look at this post from FAQ how to hide global search block - Link. From version 2.0. you'll be able to do that from table settings. 

    Also if you are using MySQL tables that will return a lot of rows it is recommended to enable Server-side processing feature and tables will be loaded more quickly.

  • Nadeem replied

    Thank you Milos.  That worked like a charm.  I appreciate your help.  Please close the ticket now.

  • [deleted] replied

    Hi Nadeem,

    You are welcome. We'd greatly appreciate it if you could take a minute and leave a review on CodeCanyon on this link. Thanks!