How to show data on a table

时间:2016-10-18 作者:Marcello Ruoppolo

我试图用wpdb类显示数据库中的一些数据,我也使用WP_List_Table类。

所以我得到了这个密码:

$wunder_plans_data = array();

foreach ($wpdb->get_results( \'SELECT * FROM \' . $wpdb->prefix . \'wunder_plans\' ) as $row ){
    $data = array(
      \'ID\' => $row->plan_id,
      \'plano\' => $row->plan_name,
      \'dias\' => $row->plan_days,
      \'valor\' => \'R$ \' . number_format( $row->plan_price, 2 ,\',\',\'.\' )
    );

    $wunder_plans_data[]=$data;
}
但当我测试时,它是这样的:

The table output

我怎样才能解决这个问题?

非常感谢你

1 个回复
SO网友:Marcello Ruoppolo

我发现了问题所在,只需切换此选项:

  function column_default($item, $column_name){
    switch($column_name){
        case \'rating\':
        case \'director\':
            return $item[$column_name];
        default:
            return print_r($item,true); //Show the whole array for troubleshooting purposes
    }
}
对此:

function column_default($item, $column_name){
    switch($column_name){
        case \'id\':
            return $item[\'plan_id\'];
        case \'plano\':
            return $item[\'plan_name\'];
        case \'dias\':
            return $item[\'plan_days\'];
        case \'valor\':
            return \'R$ \' . number_format($item[\'plan_price\'], 2 ,\',\',\'.\');
        default:
            return print_r($item,true); //Show the whole array for troubleshooting purposes
    }
}

相关推荐