我已经在前端帖子提交页面中创建了动态添加/删除字段。我使用wp_json_encode
和$wpdb->insert
将数据插入我的自定义WordPress数据库表。系统工作正常。
数据存储在我的自定义表的“reward\\u details”列中。。它看起来像:
{"reward_amount":["500","250","20000","3000"],"reward_title":["Horse","Cat","Tiger","Monkey"],"reward_description":["Horse Home","Cat Home","Tiger Home","Monkey Home"]}
但是,我无法使用检索和显示数据
json_decode
. 以下是我的代码:
<?php $project_id = $_SESSION[\'project_id\']; global $wpdb; $string = $wpdb->get_results( "SELECT reward_details FROM wpxa_rewards WHERE project_id = $project_id" );
$someArray = json_decode($string, true);
$count = count( $someArray );
for ( $i = 0; $i < $count; $i++ ) { ?>
<div class="panel panel-default">
<div class="panel-body">
<?php echo $someArray[$i]["reward_title"]; ?>
</div>
</div>
<?php } ?>
我想动态检索和显示数据…Plz帮助…