Okay
  Public Ticket #3660033
SQL Query
Closed

Comments

  • John started the conversation

    Hi there

    Loving the plugins. Quick question, how can I add SQL query functionality %LIKE% ? I need to select data from an SQL database if one of the columns contains a particular value but the plugin query doesn't allow that. ie.

    SELECT * FROM Curriculum WHERE units LIKE %116%

  •  1,767
    Miloš replied

    Hi John,

    I just did some tests with our dummy SQL Tables and I can confirm this works, our SQL Parser allows the LIKE operator.

    Just make sure to 'wrap' your value inside quotes, like this, for example, you can try on our Demo Table 1 on this back-end Page :

    https://sandbox.wpdatatables.com/wp-admin/admin.php?page=wpdatatables-constructor&source&table_id=1

    Try the Query like this, to filter the 'firstname' column as any names which contain the letter m as part of the value, like :

    SELECT * FROM dummy_employees
    WHERE firstname LIKE 'm%'

    6277604860.png
    5290043019.png

    Let me know if that works for your use-case/ table.

    Thank you.

    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

  •  1,767
    Miloš replied

    Hi John,

    My apologies, I just made a typo there and edited the Query, now it looks like this :

    SELECT * FROM dummy_employees
    WHERE firstname LIKE '%m%'
    

    So now the LIKE operator is actually doing what it's supposed to on that Table :

    7282045080.png
    4466324435.png

    As mentioned, you can test this on our Demo SQL Table #1 back-end and see how it works;

    then try to implement it in the same way on your table;

    Let me know how it goes and if you encounter further issues.

    Thanks.

    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

  • John replied

    Hi Milos

    Thank you for getting back to me so quickly. Perfect! yes - it works exactly as hoped.

    Taking this further,  I also tried LIKE '%%CURRENT_POST_ID%%' and it also works! That will save me hard-scripting tables! 

    As a small aside, is there a way to make table rows have a CSS height, (odd and even classes)? I tried with CSS but it doesn't seem to work.

    Many thanks

    John

  • John replied

    Hi there

    With the LIKE query, the data is showing in the table as expected. However, I noticed that the filters no longer work. I have Powerful filters 1.4.5 installed and when I don't use LIKE they work. With LIKE, the data shows in the table and is not hidden before filtering as it is when not using LIKE.

    Is there a workaround?

    Thanks

    John

  •  1,767
    Miloš replied


    Hi John,

    I am glad to see it initially worked, at least to show the data in the table as expected.

    Now, to the new questions :

    1. As a small aside, is there a way to make table rows have a CSS height, (odd and even classes)? I tried with CSS but it doesn't seem to work.

    -

    If you just need to manipulate the row height for the cells data,  not including the Header row,

    you can try this CSS :

    table.wpDataTable tr > td {
        height: 300px !important;
    }
    6158855726.png

    You can choose either "line height" property, or "pixels" for the height and see what is best for your use-case.

    If you need it just for one table, add it to table's settings/Customize/Custom CSS,

    or if you need same style for all tables, add it to main plugin settings/Custom JS and CSS/Custom CSS.

    -

    For the header row, you can use this selector :

    .wpDataTablesWrapper table.wpDataTable thead tr th {
      
      line-height: 4 !important;
     }

    And that will affect the row height of the header row, too.

    If you have multiple Tables on the same Page, and you wish to 'target' a specific Table ID with CSS, you can add the table ID like this :

    table.wpDataTable.wpDataTableID-1 thead tr th { 
       line-height: 6 !important;}
    table.wpDataTable.wpDataTableID-1 tr > td { 
       height: 300px !important;}

    Just make sure to change the "1" to your Table ID.

    So, you can try with either line-height or with pixel height, and see what works best for your use-case.

    When it comes to odd having one height and even row having another height :

    For the 'odd rows', you can do :

    table.wpDataTable tr.odd td {
        height: 200px !important;
    }

    4682804984.png

    For only targetting 'even rows', you can do this selector :

    table.wpDataTable tr.even td {
        height: 120px !important;
    }

    9708349017.png


    3. For not being able to properly filter with the "LIKE" operator, it might take some time for our end to test to create the same use-case as you did in order to determine the behaviour.

    It could help us to save time if you already have this setup on your own table so if we can make a duplicate from your table on your Site and to investigate it remotely, it can help us to copy what you did quicker and to isolate it.

    So could you please first record a Video of your screen to show us the steps, how the filtering issue happens;

    and if you have another duplicate of the same SQL Query, only without the "LIKE", how that behaves differently?

    If the Video gets too large, you can upload it to weTransfer and send a download link.

    And please make sure to send this in a PRIVATE reply, just to be safe, since you will be showing us the details of your back-end setup, etc.


    Let me know if that sounds OK and if you can send us the Video.

    Then if you can send me the URL of the Site and Administrator User credentials so we can try to isolate it on your Site;

    and we can try to reproduce a similar setup here to see if it is a bug or just a current limitation of our filtering with the SQL Parser, etc.

    Thank you.


    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

  • John replied

    Hi there

    I have sent a video to you via weTransfer - it will be from my email address to you.

    Thanks

    John


    The row height worked perfectly btw.

  •  1,767
    Miloš replied

    Hi John,

    Thank you for the Video, I can now see how it happens on your Page.

    If I see it on the video correctly, it seems that the Table is hiding correctly on the Back-End before filtering and it is somehow not hidden only on the front-end Page when you add that "LIKE" in the Query?

    -

    When I tried on one of my SQL Tables, I used the same 'method' to use the LIKE and to filter on a current POST ID from the Page, but I was not able to reproduce any issues.

    Please download my Video here, you can see how it works for us to add the "LIKE" in the Query along with the Placeholder Current Post ID and on our Page, the table is properly hidden.


    - Can you try removing the "ORDER BY" part of your Query, and check if that helps?

    - If not, can you try what happens if you disable 'server-side processing' option?

    6594045602.png

    Our goal is to isolate what seems to be causing that strange behaviour of not hiding the table before filtering on your end.


    If you still can't isolate it, can we take a remote look?


    Please provide me a temporary WP-admin (administrator) user for your website where this happens, 

    as well as FTP credentials and access to the database ( either link with credentials for PHPmyAdmin, or access to Hosting Panel),

    so we could log in and take a look ‘from the inside’ as that’s the most efficient way to see and resolve the issue. 

    We do not interfere with any data or anything else except for the plugin (in case that’s a production version of the site), and of course, we do not provide login data to third parties. 

    You can write credentials here just check PRIVATE Reply so nobody can see them except us.


    And please send me the URL of the Table's front-end Page.

    Thank you.


    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

  •   John replied privately
  •  1,767
    Miloš replied

    Hi John,

    My apology for the delay.

    We are investigating this now, and I will advise you when we check all the details.

    I am able to log in as Admin and going to check both tables, pages and all the details with tabs as you advised on the second Page.

    We will report back with an update as quickly as possible.

    Thank you for your patience and cooperation.

    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

  •   Miloš replied privately
  • John replied

    Hi Milos

    Thank you for your reply.

    This is bizarre. When I go to the url directly by pasting https://vistacurriculum.com/castles-and-bridges/ into the browser, I now see the drop down options for filtering.

    However...

    If you select menu option 'unit plans -> two year cycle' 

    Then 'Cycle B -> Castles and bridges'

    Then 'Progression -> history' or 'progression -> geography' then the filters don't show.

    Very weird.

    If you right click on the Castles and Bridges image and select open link in new window then the filters appear!

    It seems like opening in the same browser window is affecting the filters.

    John

  • John replied

    Hi Milos

    Update...

    The behaviour is definitely when the post is loaded following a link from the 'unit plans' page. The filters don't show the dropdown options. Right-clicking the castles image on the units plan page and 'open in new tab' - everything works. Opening the post directly in a browser tab works as expected.

    I've de-activated all but the essential plugins and no change in behaviour.

    I added the addition % % around the current_post_id because the database column for the learning objectives has a column with all the units that the objective is relevant to, for example posts 116, 2017 - without the extra % % the database line is not returned in the list -  so the query becomes a %LIKE% rather than just LIKE.

    I've also tried just calling the shortcake for the history progression table with no accordion but the same result.

    John

  •  1,767
    Miloš replied

    Hi John,

    Thank you for these updates from your end.

    I can see this is turning out to be a much more complicated issue than it originally seemed, unfortunately.

    My apologies for all the waiting time, we will do our best to try to isolate it with your updates and the details as described.

    As soon as we check everything, we will report back as quickly as possible.

    Thank you for your patience and cooperation once again.

    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

  • John replied

    Hi. Milos

    I think I may have narrowed it down to %CURRENT_POST_ID%

    First, I created a different way of calling data for some tables which is actually more efficient than using LIKE - this is table ID=16

    I added this shortcode to the post and same thing - no data. However...

    If I replace %CURRENT_POST_ID% with 116 which I know is the post ID then it works perfectly.

    I then duplicated the original LIKE table (ID 17) and replaced %CURRENT_POST_ID% with 116 and it works perfectly.

    So, it looks like the %CURRENT_POST_ID% isn't getting the post ID either correctly of quickly enough, resulting in no data. 

    I'd rather use %CURRENT_POST_ID% because otherwise I will have so many tables, which is fine unless I need to tweak a table. Instead of doing it once, I'd need to replicate a change multiple times.

    Hope this helps.

    John