2
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 encode the results of this query? Thanks

Ryan
  • 14,392
  • 8
  • 62
  • 102
  • 2
    **Warning** your code appears to be susceptible to sql injection attacks. – Daniel A. White Sep 26 '11 at 23:42
  • tried casting the result object as an array and passing it to json_encode()? – Jonathan Kuhn Sep 26 '11 at 23:43
  • This question seems similar, and the first answer seems pertinent; if you have more specific needs perhaps you could update your question? http://stackoverflow.com/questions/383631/json-encode-mysql-results – Zach Snow Sep 26 '11 at 23:44

1 Answers1

5
$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);
webbiedave
  • 48,414
  • 8
  • 88
  • 101
timdev
  • 61,857
  • 6
  • 82
  • 92