dqst96444 2016-12-31 17:10
浏览 36

Wordpress:CalderaWP将MySQL字段值存储为字符串“Array”。 如何用$ wpdb解析?

I've built a survey site with Wordpress and CalderaWP forms and I'm running into an issue with the data storage for checkbox field values. My concern is that the data for these types of form submissions are being stored in the MySQL database as the string, "Array". Here is an example:

enter image description here

I have a number of things I'd like to do with this data, such as export it to a csv file, allow admins to change values via custom fields, etc. and in every front end form I've created the value shows up as the string, "Array". Here is a shot of one of the custom fields:

enter image description here

I've decided to write a wp cron that reformats this data into a front-end, usable format. The first part is getting the data and converting it. I've managed to use the $wpdb object to get all the fields that have the value "Array". It looks like this:

function reformat_mysql_arrays() {
    global $wpdb;
    $table_name = '`wp_mydatabase`.`wp_cf_form_entry_values`';
    $results = $wpdb->get_results("SELECT * 
                                   FROM $table_name 
                                   WHERE `value` LIKE 'Array'
                                   ");

    // Loop through the rows for the query
    foreach($results as $key => $row) {

        // Loop through the current row's columns
        foreach($row as $column => $value) {

            if($column == 'id') {
                echo 'ID: ' . $value . ' | ';
            }

            if($column == 'value') {
                var_dump($value);
            }
        }

    }// END foreach column loop

}
reformat_mysql_arrays();

My concern is that when I var_dump() the field value from the 'value' column, it appears to literally be the string, "Array", rather than an array I can parse. Here's a screen shot of the output of this function:

enter image description here

I've attempted every way I can think of to parse the values -- explode, implode, foreach, unserialize, array_values, etc. -- and I still cannot get any value out of the apparent array. Any help would be greatly appreciated. Am I missing something here?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题