et4891 Posted October 3, 2013 Share Posted October 3, 2013 I have three text box for people to enter as numbers and stores in json <?php add_option('angels_'.date("ymd-His"), json_encode($_POST)); ?> The data stored in the database looks like {"angle1":"60","angle2":"60","angle3":"90","submit":"Submit"} the above is also what I get what I called out the data from the database I used this code to call out the data <?php $sql = "SELECT * FROM wp_options WHERE option_name LIKE 'angels%' ORDER BY option_name"; $options = $wpdb->get_results($sql); foreach ( $options as $option ) { esc_attr($option->option_value).PHP_EOL; } $values = esc_attr($option->option_value); echo $values; ?> The output gives me {"angle1":"60","angle2":"60","angle3":"90","submit":"Submit"} if I only want to get the numbers 60/60/90 individually how can I do that? Link to comment https://forums.phpfreaks.com/topic/282672-how-to-properly-json-decode-and-use-the-keyvalue/ Share on other sites More sharing options...
vinny42 Posted October 3, 2013 Share Posted October 3, 2013 How about json_decode()? :-) Or use a database that can deal with JSON, like PostgreSQL. Link to comment https://forums.phpfreaks.com/topic/282672-how-to-properly-json-decode-and-use-the-keyvalue/#findComment-1452387 Share on other sites More sharing options...
et4891 Posted October 3, 2013 Author Share Posted October 3, 2013 How about json_decode()? :-) Or use a database that can deal with JSON, like PostgreSQL. so I should do something like below? $options = json_decode($wpdb->get_results($sql),true); Link to comment https://forums.phpfreaks.com/topic/282672-how-to-properly-json-decode-and-use-the-keyvalue/#findComment-1452388 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.