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 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 lammps拉伸应力应变曲线分析
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
    • ¥30 python代码,帮调试,帮帮忙吧
    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建