douluozhan4370 2017-08-03 16:49
浏览 33

特殊的mysql调用获取行数

in Wordpress/WooCommerce MySQL database i have various shortcodes.

If there is 2 orders in the database then one of the orders is a shop_order and the next one is shop_subscription_order. We find those 2 datas in another tabel by calling post_id, which is named wp_posts. There we have to look on the shop_subscription_order if the order is wc_active. We need one mySQL call that looks on how many rows there is on each customer, if there is 2 rows it has to take post_id on the subscription_order and check if it is wc_active, and print all orders with that status.

A not working example but for show what i mean: SELECT * from post_meta where meta_key=´_customer_id´ and meta_vlaue=´$customerid´ if number of rows='2' select * from wp_post where post_type='shop_supscription' whit the id form post_meta and post_status='wc-active'

and then echo num_of_rows

video example here:

Https:// nltrading.dk/video.mov

First in the video we show an order with 3 rows, and after we show an order with 2 rows.

We only need the orders with 2 rows, where there is an wc_active as shown in the video. We need to call all of this to count the number of rows where there is an wc_active whit only 2 rows of orders.

  • 写回答

1条回答 默认 最新

  • dra8603 2017-08-03 16:52
    关注

    Use this like code:

    //To show number of rows in table
    function test()
    {
        global $wpdb;
        $table_name = $wpdb->prefix . 'mydata';
        $count_query = "select count(*) from $table_name";
        $num = $wpdb->get_var($count_query);
        echo  $num . 'Rows Found';
    }
    
    评论

报告相同问题?