Hi, I use complex queries, so after updating to wpDataTables 2.0 I had to create some views in MySQL. To prevent having to create many views I created a view which uses 2 variables in its SELECT statement. For this I used an example I found on stackoverflow.com
The example function:
create function p1() returns INTEGER DETERMINISTIC NO SQL return @p1;
and the view:
create view h_parm as
select * from sw_hardware_big where unit_id = p1() ;
Then you can call a view with a parameter:
select s.* from (select @p1:=12 p) parm , h_parm s;
I tried this in phpMySQL and I got my view working, also I created a working query passing 2 variables to the view.
Next step I tried to copy the query to the wpDataTables (create a Table) where it looks like this:
SELECT gm.meting as "meting", gm.datum as "datum" FROM
(select @aquaID:=2 a) ap,
(select @pinID:=11 p) pp,
week_gemiddelden_per_dag gm
ORDER BY gm.datum
However, when I press the save button in wpDatatables I get an error message:
Error
cannot calculate position of @aquaID within @aquaID:=2 a) ap, (select @pinID:=11 p) pp, week_gemiddelden_per_dag gm ORDER BY gm.datum
Is there any way to use functions in wpDataTables?
Our recommendation when creating mysql tables is not to use functions like SUM, GROUP BY, ORDER BY, LIMIT , JOIN etc. You have a complicated query and my suggestion is to make a just a VIEW in phpmyadmin without any functions like
thats the thing, i have created a view in mySQL. but to prevent me from having to create a whole bunch of views, I would like to pass a variable to the view.
SELECT * FROM [view_name] is not enough if you want to pass a variable to the view.
This is where my question comes in, i did manage to find a working solution using functions in mySQL, however this does not seem to work in wpDataTables.
Sorry to disappoint you but unfortunately variables in mysql queries are not supported. But you can use placeholders. You can take a look at our documentation about placeholders here.
Hi, I use complex queries, so after updating to wpDataTables 2.0 I had to create some views in MySQL. To prevent having to create many views I created a view which uses 2 variables in its SELECT statement. For this I used an example I found on stackoverflow.com
The example function:
and the view:
Then you can call a view with a parameter:
I tried this in phpMySQL and I got my view working, also I created a working query passing 2 variables to the view.
Next step I tried to copy the query to the wpDataTables (create a Table) where it looks like this:
However, when I press the save button in wpDatatables I get an error message:
Error
cannot calculate position of @aquaID within @aquaID:=2 a) ap, (select @pinID:=11 p) pp, week_gemiddelden_per_dag gm ORDER BY gm.datum
Is there any way to use functions in wpDataTables?
Hi Richard,
Thank you for your purchase/
Our recommendation when creating mysql tables is not to use functions like SUM, GROUP BY, ORDER BY, LIMIT , JOIN etc. You have a complicated query and my suggestion is to make a just a VIEW in phpmyadmin without any functions like
SELECT * FROM view_name
Kind Regards,
Isidora Markovic
wpDataTables: FAQ | Facebook | Twitter | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Amelia demo sites | Docs
You can try our wpDataTables add-ons before purchase on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables
Hi Milan,
thats the thing, i have created a view in mySQL. but to prevent me from having to create a whole bunch of views, I would like to pass a variable to the view.
SELECT * FROM [view_name] is not enough if you want to pass a variable to the view.
This is where my question comes in, i did manage to find a working solution using functions in mySQL, however this does not seem to work in wpDataTables.
Is there any way?
Hi Richard,
Sorry to disappoint you but unfortunately variables in mysql queries are not supported.
But you can use placeholders.
You can take a look at our documentation about placeholders here.
Kind Regards,
Isidora Markovic
wpDataTables: FAQ | Facebook | Twitter | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Amelia demo sites | Docs
You can try our wpDataTables add-ons before purchase on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables