Okay
  Public Ticket #3390278
Writing query to get a wpdatatables table fields from PHP
Closed

Comments

  • Damien BECHERINI started the conversation

    Hello,

    I need to be able to store data coming from an Excel file in the database (a price list with a few columns). Your plugin seem perfect for that.

    Then I will make a frontend form asking visitors for specific values and an ajax request will send this data to the server. Then I need to query the database from PHP with the visitor form values to get the rows I need and show the correct price extracted from the query result.

    I didn't find how to make SQL queries from PHP to wpdatatables in your documentation, can you lead me to the correct page or explain me how I can know the name of the tables I will have to query for?

    Thanks in advance,

    Best regards,

    Damien

  •  1,699
    Miloš replied


    Hi ,Damien.

    Firstly, I would like to sincerely apologize for the delayed response as we have been experiencing an unusually high number of tickets. I am sorry that it has taken longer than usual to respond to your concern and your patience is highly appreciated.

    -

    Using PHP to conduct SQL Queries is not something that is built-in as a user-friendly solution with our plugin.

    We have separate methods,

    for example 

    1. When we need to import data from Excel, that is easy , you can just follow this Documentation.

    2. When we need to make SQL Query based Tables ,you can see this Documentation.

    Please note: Using this plugin feature requires at least a basic knowledge of SQL. It is assumed that you can create the table in some MySQL data manager (e.g., PHPMyAdmin, MySQL Workbench), and prepare a SQL query that will return the data you need. If you do not know how to use MySQL, refer to the “Create a MySQL-query-based table by generating a query to MySQL database” section. It will explain how to create complete tables or MySQL queries without this basic knowledge. Please be advised that preparing MySQL queries for you is not included in the plugin support.

    -

    3. For making tables linked to PHP Array,  you can try this :

    Creating Tables in WordPress based on serialized PHP arrays.

    -


    But what you described here, in terms of using PHP to pull data from SQL Tables,

    i am sorry, but this would require a custom solution that is beyond what our Support can cover.

    At this time, we do not have an ideal working solution to share,

    but i did my best to at least find some example that is perhaps remotely similar.


    One of our users wanted to convert the values in one of the columns to a link that when clicked will run another query passing in the value clicked as a variable in MySQL and then display a second table with the new data.

    -

    This is how we first advised him, to construct the column by using CONCAT with our SQL Query based tables :

    if there's a page on your website, that contains a string from a column (for example "page1" ), you can use CONCAT function, like:

    SELECT column1,
            CONCAT('<a href="www.yourwebsite.com/',yourTable.column2,'/">',yourTable.column2,'</a>') AS LINK
    FROM yourTable
    

    That would append "page1" found in column 2 to www.yourwebsite.com/, so the generated link would be www.yourwebsite.com/page1/, hyperlinked behind "page1" - entry in the cell.

    -

    The user then installed "Insert PHP Code Snippet", and this is what he said :

    "Using that plugin, I created a shortcode that look like this:

    Shortcode Name: GetReport

    <?php echo do_shortcode('[wpdatatable id=4 var1="' . $_GET['ID'] . '"]'); echo do_shortcode('[wpdatatable id=3 var1="' . $_GET['ID'] . '"]'); ?>

    Then in my page where the table is generated, I insert the shortcode below to display the tables using the ID param from the URL:

    [xyz-ips snippet="GetReport"]

    Hopes that can help the others looking for a solution".

    -


    I hope that this might help in any way.

    If you wish to see a user-friendly solution for this use-case,

    you can suggest it to our developers - they will do their best to make a solution in the future.

    Please feel free to search on our suggestions page

     to see if someone may be already suggested this feature. If you can't see it, feel free to add your suggestion there,  and as more people vote, the feature will move higher on the priority list.

    You can certainly follow our changeLog page if you'd like ( it is also available in the plugin dashboard), where we state any changes/new features/bug fixes during updates;

    and our newsletter, so you're informed about new features, bug fixes, freebies, etc.

    -

    If you have coding skills and wish to try to make a custom solution now,

    you can check out our available hooks for Developers on this documentation and see if you can find any hook that might help.

    Please be advised that custom solutions with hooks are not included in our support.

    You can also research resources such as Stack Overflow to see if any other user perhaps found a workaround.

    ( We do like to give examples for certain solutions, but for this use-case, we, unfortunately, don't have anything yet)


    And i just wanted to point out that you can try wpDataTables before purchasing

     on our sandbox Demo sites ( you can find links for the main plugin Demo,  

    as well as add-on Demos, in my signature),

    and there is a 15-day money-back guarantee period, 

    so if you purchase the plugin, you can safely fully test it out, and if it doesn't fit your needs you can request and receive a refund in that period. ( same goes for all plugins and add-ons)

    Let me know if you have any additional questions. smile.png


    Kind Regards, 

    Miloš Jovanović
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  •   Damien BECHERINI replied privately
  •  1,699
    Miloš replied

    Hi, Damien.

    No problem, i am happy to advise.

    I am pretty sure you should be able to achieve this, but i do not have experience personally with calling tables through PHP, rather than through a shortcode, so I'm not 100% sure what's the best way.

    I can confirm that if you import data from an Excel ( documentation in more details about that here), 

    this creates a new Manual Table in your database, which will have its own set of columns and rows;


    so it will be editable in our Plugin,

    and you can also make new SQL Query based tables easily from this data,

    and you can also later update this existing Manual Table by uploading a CSV/Excel/Google Sheet.

    -

    2. I will ask our developers if they have any working example or at least a confirmation if it will be possible for you to use PHP with custom logic to call data from the database table,

    rather than printing PHP with the plugin shortcode.

    As soon as they advise, i will report back to confirm that.

    Thank you for your patience.



    Kind Regards, 

    Miloš Jovanović
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  •  2,499
    Aleksandar replied

    Hello Damien.

    You can do this only for manual or imported tables. The name of the table can be found in the "MySQL table name" field, in the Editing tab, and you can use it in custom queries in PHP that you wish to create.

    How you'll get the code and what queries you'll use doesn't fall under included support for the plugin, so we wouldn't be able to help you with that.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables