I’m sure the answer is yes. But how would I write this differently?
$query = $this->db->get_where('online_ads', array('id' => 20))->row()->size;
$ad_array = json_decode($query, TRUE);
$result = '';
foreach ($ad_array as $a):
$query = $this->db->get_where('ad_sizes', array('id' => $a))->row();
$result .= $query->name.' ';
endforeach;
echo $result;
Write a query to join online_ads and ad_sizes. Yes, you will have redundant data from the online_ads table, but if ad_sizes has large resultset, the net execution time will be much faster.