DaDaBIK
This forum is devoted to the discussion about the software DaDaBIK database front-end
the PHP Database application generator for MySQL, PostgreSQL and SQLite; also available for Wordpress.

Welcome! Log In Create A New Profile

Advanced

Custom button that uses a filtered query

Posted by taubes 
Custom button that uses a filtered query
April 02, 2019 02:51AM
Hi,

I hope somebody can help me here.

I am using a custom button to generate a custom PDF from the results_grid (see below). The only variable that I can use is $table_name. Is there a way to access the filter, set by search and quick search in my custom_function.

(...)
$custom_buttons['some_table'][$cnt]['callback_function'] = 'dadabik_custom_function';
$custom_buttons['some_table'][$cnt]['show_in'] = 'results_grid';
(...)
function dadabik_custom_function($table_name, $where_field, $where_value) {
global $conn;

$sql = "SELECT * FROM :table_name ";
$res_prepare = prepare_db($conn, $sql);
$res_bind = bind_param_db($res_prepare, ':table_name', $table_name);
$res = execute_prepared_db($res_prepare,0);
$row = fetch_row_db($res_prepare);
(...)
}

What I would like to do is:

(...)
$custom_buttons['some_table'][$cnt]['callback_function'] = 'dadabik_custom_function';
$custom_buttons['some_table'][$cnt]['show_in'] = 'results_grid';
(...)
function dadabik_custom_function($table_name, $where_field, $where_value) {
global $conn;

$filter = xxx; // something like WHERE username_user = 'xxxx' AND year = 'xxxx'

$sql = "SELECT * FROM :table_name :filter";
$res_prepare = prepare_db($conn, $sql);
$res_bind = bind_param_db($res_prepare, ':table_name', $table_name);
$res_bind = bind_param_db($res_prepare, ':filter', $filter);
$res = execute_prepared_db($res_prepare,0);
$row = fetch_row_db($res_prepare);
(...)
}

Thanks so much for your help

Stefan

+++ using DaDaBIK version 9.2.2-Monterosso enterprise
Re: Custom button that uses a filtered query
April 03, 2019 03:43AM
Hello Stefan,
you can find the current WHERE clause produced by search & filters in the global variable $where_clause.
So add it to your custom function:

global $conn, $where_clause

and use it.

Best,

________________________________________________________
Eugenio |\.-./| DaDaBIK developer and project admin
Re: Custom button that uses a filtered query
April 03, 2019 05:21AM
Awesome, that was easy ;-)

Is there a resource where one can look up global or session values?

Thanks

Stefan
Re: Custom button that uses a filtered query
April 03, 2019 06:01AM
Hi,
not yet, but I want to add a section about it in the documentation.

Best,

________________________________________________________
Eugenio |\.-./| DaDaBIK developer and project admin
Sorry, only registered users may post in this forum.

Click here to login