Okay
  Public Ticket #1072800
BUG Possible values with placeholders
Closed

Comments

  •  1
    p4nthere started the conversation

    Hello.

    wpDatatable 1.7.1

    If i have a mySQL table where i use placeholders like SELECT * FROM `table` WHERE `row` = %VAR1%

    I cannot auto fill the possible values via button "create from column values", nothing happens when i press the button. I have set default VAR1 value and in preview table showing data.

    If i delete the where statement in query and save when the auto fill possible values work.

    Inform me if you need temp admin. 


  • [deleted] replied

    Hi p4nthere,
    Thank you for the purchase.

    Please provide me a temporary WP-admin login for your site where this happens, 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 party. You can write credentials here just check PRIVATE so nobody can see it except us.

  •   p4nthere replied privately
  • [deleted] replied

    Hi p4nthere,

    Can you send me your FTP account credentials so I can fix this issue?

  •   p4nthere replied privately
  • [deleted] replied

    Hi p4nthere,

    I can't login with these credentials to your FTP account. Can you go in file ../wp-content/plugins/wpdatatables/controllers/wdt_admin_ajax_actions.php search for this function:

    /**
     * Get all distinct values for the column
     */
    function wpdatatable_get_column_distinct_values(){
        $dist_vals = array();
        $table_id = (int)$_POST['table_id'];
        $column_id = (int)$_POST['column_id'];
        $table_data = wdt_get_table_by_id( $table_id );
        if( $table_data['table_type'] !== 'mysql' && $table_data['table_type'] !== 'manual' ) {
            _e('Wrong table type!','wpdatatables');
            die();
        }
        $column_data = wdt_get_column_data( $column_id );
        $mysql_table_query = $table_data['content'];
        $original_column_name = $column_data['orig_header'];
        $dist_vals_query = "SELECT DISTINCT(`$original_column_name`) AS `$original_column_name` FROM ( $mysql_table_query ) tbl";
        if(!get_option('wdtUseSeparateCon')){
            global $wpdb;
            $dist_vals = $wpdb->get_col( $dist_vals_query );
        } else {
            $sql = new PDTSql(WDT_MYSQL_HOST, WDT_MYSQL_DB, WDT_MYSQL_USER, WDT_MYSQL_PASSWORD, WDT_MYSQL_PORT);
            $rows = $sql->getArray( $dist_vals_query );
            foreach ($rows as $row) {
                $dist_vals[] = $row[0];
            }
        }
        echo json_encode( $dist_vals );
        exit();
    }
    add_action( 'wp_ajax_wpdatatable_get_column_distinct_values', 'wpdatatable_get_column_distinct_values' );

    And replace it with this one:

    /**
     * Get all distinct values for the column
     */
    function wpdatatable_get_column_distinct_values(){
        global $wdt_var1, $wdt_var2, $wdt_var3;
        $dist_vals = array();
        $table_id = (int)$_POST['table_id'];
        $column_id = (int)$_POST['column_id'];
        $table_data = wdt_get_table_by_id( $table_id );
        $wdt_var1 = $wdt_var1 === '' ? $table_data['var1'] : $wdt_var1;
        $wdt_var2 = $wdt_var2 === '' ? $table_data['var2'] : $wdt_var2;
        $wdt_var3 = $wdt_var3 === '' ? $table_data['var3'] : $wdt_var3;
        if( $table_data['table_type'] !== 'mysql' && $table_data['table_type'] !== 'manual' ) {
            _e('Wrong table type!','wpdatatables');
            die();
        }
        $column_data = wdt_get_column_data( $column_id );
        $mysql_table_query = $table_data['content'];
        $original_column_name = $column_data['orig_header'];
        if ( $wdt_var1 || $wdt_var2 || $wdt_var3 ) {
            $mysql_table_query = WDTTools::applyPlaceholders( $mysql_table_query );
        }
        $dist_vals_query = "SELECT DISTINCT(`$original_column_name`) AS `$original_column_name` FROM ( $mysql_table_query ) tbl";
        if(!get_option('wdtUseSeparateCon')){
            global $wpdb;
            $dist_vals = $wpdb->get_col( $dist_vals_query );
        } else {
            $sql = new PDTSql(WDT_MYSQL_HOST, WDT_MYSQL_DB, WDT_MYSQL_USER, WDT_MYSQL_PASSWORD, WDT_MYSQL_PORT);
            $rows = $sql->getArray( $dist_vals_query );
            foreach ($rows as $row) {
                $dist_vals[] = $row[0];
            }
        }
        echo json_encode( $dist_vals );
        exit();
    }
    add_action( 'wp_ajax_wpdatatable_get_column_distinct_values', 'wpdatatable_get_column_distinct_values' );

    This issue will be fixed in version 2.0.

  •  1
    p4nthere replied

    ok i will try it.

  •  1
    p4nthere replied

    ok Milos it's working.

    Thanks

  • [deleted] replied

    Hi p4nthere,

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