【发布时间】:2017-10-11 09:09:56
【问题描述】:
我无法打印此查询返回的数组键的值:
$user1 = $wpdb->get_results(
"select product,checked_by,date(submit_date) from diary_user_form_storage where DATE(submit_date) = CURDATE() ;
");
$jsonString = "";
foreach ($user1 as $key => $value) {
$productString = stripslashes($value->product);
$checked = stripslashes($value->checked_by);
$suppliers = stripslashes($value->suppliers);
$van_temperature = stripslashes($value->van_temperature);
$comments = stripslashes($value->comments);
$product = json_decode($productString, true);
$checked_by = json_decode($checked , true);
$suppliers = json_decode($suppliers , true);
$van_temperature = json_decode($van_temperature, true);
$comments = json_decode($comments, true);
//This code is running for single variable $product But I have to print all //multiple variable here . How can I print multiple variable here
foreach ($product as $v){
echo $v['product'];
}
}
?>
这是打印出来的结果
[1]=>
array(1) {
["product"]=>
string(5) "GSSHS"
}
}
如果我为我的 SQL 查询 print_r($user1) 做了 print_r,那么输出就是你可以看到的数组列表。
[1] => stdClass Object
(
[store_id] => 2
[user_id] => 7
[unit_data] => [{\"unit_data\":\"10\"}]
[suppliers] =>
[product] => [{\"product\":\"AA\"}]
[checked_by] => [{\"checked_by\":\"Rakesh Kushwaha\"}]
[temperature_in] => [{\"temperature_in\":\"QWW\"}]
[temperature_out] =>
[time_in] => [{\"time_in\":\"44:44\"}]
[time_out] =>
[van_temperature] =>
[center_temperature] =>
[cooling_temperature] =>
[end_cooling_temperature] =>
[comments] =>
[submit_date] => 2017-10-18 22:12:39
[time_holded] =>
[temperature] =>
[time_reheated] =>
[extra_timing] =>
[image_url] =>
[category_name] => opening
[category] => [{\"category\":\"Frozen\"}]
)
我只需要数组这个键的值:["product"]=>"GSSHS"
【问题讨论】:
-
请您打印所有结果,以便您可以在 foreach 之前将 var_dump 放在 $product 上,var_dump($product)
-
您好,能否打印一下所有结果:$user1 内容?
-
Hassan Ali Salem @是的,我可以打印
-
你好桑杰,我更新了答案,试试看告诉我