我正在制作一个wordpress插件,我使用了一个查询来从数据库中获取所需的所有数据,但之后我无法弄清楚如何解析它。
我的查询是:
$dbContent = $wpdb->get_results( "SELECT option_id, option_name, option_value FROM wp_options WHERE option_name LIKE '%Customizer%'" );
我正在使用:
显示它$retval .= "<pre>";
$retval .= print_r($dbContent);
$retval .= "</pre>";
我明白了,我认为是一个数组数组:
Array ( [0] => stdClass Object ( [option_id] => 119587 [option_name] => bfhCustomizer_price_1 [option_value] => 2.85 ) [1] => stdClass Object ( [option_id] => 119584 [option_name] => bfhCustomizer_option1 [option_value] => Leave-In Moisturizer ) [2] => stdClass Object ( [option_id] => 119585 [option_name] => bfhCustomizer_option2 [option_value] => Conditioner/Cleansing Conditioner ) [3] => stdClass Object ( [option_id] => 119586 [option_name] => bfhCustomizer_option3 [option_value] => Pure Oil Mixture ) [4] => stdClass Object ( [option_id] => 119588 [option_name] => bfhCustomizer_price_2 [option_value] => 3.45 ) [5] => stdClass Object ( [option_id] => 119589 [option_name] => bfhCustomizer_price_3 [option_value] => 1.99 ) [6] => stdClass Object ( [option_id] => etc...
有人可以告诉我如何正确访问它吗?我试图使用像$dbContent->option_id
或$dbContent['option_id']
这样的东西,但都没有用,我现在迷失在这里
答案 0 :(得分:1)
看起来你有一个stdClass对象数组,所以你可以像这样访问它:
$id = $dbContent[0]->option_id;
// or in a loop
foreach($dbContent as $index => $result) {
echo $result->option_id;
echo $result->option_name;
// etc
}