-5

Possible Duplicate:
encode json using php?

$hello_world = $this->session->all_userdata();
foreach($hello_world as $key=>$product_id)
{
$query['products']  = $this->Global_products->globalFindProductsViewed($product_id);
    foreach($query['products'] as $product)
{
$ryan[] = $product->name;
}

}
foreach($ryan as $r) 
{
    echo json_encode(array($r));
}

The output then looks like this: ["Alpine 50W x 4 Apple® iPod®-Ready In-Dash CD Deck"]

I know I cant access this with JavaScript. Can someone suggest how I can make this work?

Community
  • 1
  • 1
Ryan
  • 14,392
  • 8
  • 62
  • 102

1 Answers1

1

JSON encoding every array element separately doesn't make sense.

Remove the foreach, and just do a

echo json_encode($ryan);
Pekka
  • 442,112
  • 142
  • 972
  • 1,088