How can I json_encode the results of this query?
foreach($hello_world as $key=>$product_id) {
if(in_array($key,$exclude))continue;
$query = $this->db->query("SELECT * FROM product where modelNumber = '$product_id'");
if ($query->num_rows() > 0) {
foreach($query->result() as $row) {
echo $row->name;
}
}
}
Can someone give me advice as to how I would json e开发者_JAVA技巧ncode the results of this query? Thanks
$data = array();
$query = $this->db->query("SELECT * FROM product where modelNumber = '$product_id'");
if ($query->num_rows() > 0) {
foreach($query->result() as $row) {
$data[$row->id] = $row->name;
}
}
$json = json_encode($data);
精彩评论