• Resolved shadowgr

    (@shadowgr)


    Check This Photo
    Hello again ??

    i want to update my table from wordpress`s backoffice
    and display i home page /time/league/match/tip/odds/book/win_loss

    SELECT date,time,league,match,tip,odds,book,win,loss
     FROM BC_TIPS

    and in another page i want to display BETS/WIN/LOSS

    SELECT count(ID) AS Bets,count(win_loss) AS WIN
     FROM BC_TIPS
     WHERE win_loss="yes"

    its possible to do this?
    if yes where i must write my sql code and where i can take my shortcode to display my data ???

    https://www.ads-software.com/plugins/custom-database-tables/

Viewing 5 replies - 16 through 20 (of 20 total)
  • Thread Starter shadowgr

    (@shadowgr)

    Plugin Author ka2

    (@ka2)

    I am very sorry, “sort_order” in the attributes of the shortcode to filter had leaked. Correct shortcode is as follows:

    [cdbt-view table="wp_tips" display_title="false" order_cols="ID" sort_order="ID:asc"]

    I could finally confirm the operating by configuration of the table, the shortcode and the filters such as the following.

    Table structure:

    CREATE TABLE wp_tips (
      ID bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
      username varchar(100) NOT NULL,
      date_time datetime DEFAULT NULL,
      league varchar(255) DEFAULT NULL,
      match varchar(255) DEFAULT NULL,
      tip varchar(10) DEFAULT NULL,
      odds float(6,2) DEFAULT NULL,
      book varchar(10) DEFAULT NULL,
      win_loss varchar(4) DEFAULT NULL,
      PRIMARY KEY (ID)
    ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4

    Display table in main page:

    [cdbt-view table="wp_tips" display_title="false" exclude_cols="ID,username"]

    Display table in other page (post id = 23):

    [cdbt-view table="wp_tips" display_title="false" order_cols="ID" sort_order="ID:asc"]

    Code of filter hooks into the “functions.php” at the theme:

    if ( ! is_admin() ) :
    
    function wp_tips_get_data_sql( $sql, $table_name, $sql_clauses ) {
      if ( get_post()->ID === 23 && 'wp_tips' === $table_name ) {
        $_overwrite_sql = <<< SQL
    SELECT
        count(id) AS BETS,
        Sum(IF(win_loss = 'win', 1, 0)) As Wins,
        Sum(IF(win_loss = 'loss', 1, 0)) As Looses,
        Sum(IF(win_loss = 'void',1, 0)) AS Void
    FROM %s ;
    SQL;
    
    $sql = sprintf( $_overwrite_sql, $table_name );
      }
      return $sql;
    }
    add_filter( 'cdbt_crud_get_data_sql', 'wp_tips_get_data_sql', 10, 3 );
    
    function wp_tips_shortcode_custom_columns( $columns, $shortcode_name, $table ){
      if ( get_post()->ID === 23 && 'cdbt-view' === $shortcode_name && 'wp_tips' === $table ) {
        $columns = [];
        $columns[] = [
          'label' => 'BETS',
          'property' => 'BETS',
          'sortable' => false,
          'sortDirection' => 'asc',
          'dataNumric' => true,
          'truncateStrings' => '0',
          'className' => '',
        ];
        $columns[] = [
          'label' => 'Wins',
          'property' => 'Wins',
          'sortable' => false,
          'sortDirection' => 'asc',
          'dataNumric' => true,
          'truncateStrings' => '0',
          'className' => '',
        ];
         $columns[] = [
          'label' => 'Looses',
          'property' => 'Looses',
          'sortable' => false,
          'sortDirection' => 'asc',
          'dataNumric' => true,
          'truncateStrings' => '0',
          'className' => '',
        ];
         $columns[] = [
          'label' => 'Void',
          'property' => 'Void',
          'sortable' => false,
          'sortDirection' => 'asc',
          'dataNumric' => true,
          'truncateStrings' => '0',
          'className' => '',
        ];
      }
      return $columns;
    }
    add_filter( 'cdbt_shortcode_custom_columns', 'wp_tips_shortcode_custom_columns', 10, 3 );
    
    endif;

    Thank you,

    Thread Starter shadowgr

    (@shadowgr)

    It works correctly,thank you very much !you are the best. ??

    main page
    2nd page
    i will try now transfer this to my site.

    *Is possible to make o column with a photo link?(Should I make to new thread)

    Plugin Author ka2

    (@ka2)

    Yes, please make new issue about photo link.

    Plugin Author ka2

    (@ka2)

    I have closed this issue because it resolved.

Viewing 5 replies - 16 through 20 (of 20 total)
  • The topic ‘sql queries count(id)’ is closed to new replies.