Hi there,
I have a php array as follows:
<?php
$brand = array (
"nike" => array (
array( 'logo'=>'images/nike.png', 'description'1=>'some nike text'),
array( 'logo'=>'images/nike.png', 'description2'=>'some nike text'),
array( 'logo'=>'images/nike.png', 'description3'=>'some nike text')),
"puma" = array(
array( 'logo'=>'images/puma.png', 'description'=>'some puma text'),
array( 'logo'=>'images/puma.png', 'description'=>'some puma text'),
array( 'logo'=>'images/puma.png', 'description'=>'some puma text')),
"addidas" = array(
array( 'logo'=>'images/addidas.png', 'description'=>'some addidas text'),
array( 'logo'=>'images/addidas.png', 'description'=>'some addidas text'),
array( 'logo'=>'images/addidas.png', 'description'=>'some addidas text')),
"Asics" = array(
array( 'logo'=>'images/Asics.png', 'description'=>'some Asics text'),
array( 'logo'=>'images/Asics.png', 'description'=>'some Asics text'),
array( 'logo'=>'images/Asics.png', 'description'=>'some Asics text')),
"Qicksilver" = array(
array( 'logo'=>'images/Qicksilver.png', 'description'=>'some Qicksilver text'),
array( 'logo'=>'images/Qicksilver.png', 'description'=>'some Qicksilver text'),
array( 'logo'=>'images/Qicksilver.png', 'description'=>'some Qicksilver text')),
);
?>
The goal is to display the brand names ie Puma, Nike etc as hyperlinks in a div:
<div id="brand-nav">
</div>
Then when you click on one of the hyperlinks, it will load the content within the arrays. For example when you click on the Nike link, it will load the 3 array items into a div below:
<div id="brand-content">
</div>
I understand that to achieve this effect, I would be better using Javascript so that I don’t navigate away from the current page, and avoid page refreshes etc. So I believe that it would be easier to convert my php array as a JSON object.
<script type="text/javascript">
var brand = <?php echo json_encode($brand) ?>;
</script>
So now the array is a JSON object, I need to iterate over it to display just the brand names as hyperlinks.
for (var n in brand){
for (var i in brand[n]){
document.write('<a href="' + brand[n][i].logo + '">' + brand[n][i].description + '</a>');
}
}
With this code it is just dumping all the array items for every brand.
So essentially I would like to display all the brands names as hyperlinks within the brand-nav div and onClick, load all related array items for that brand.
Hope someone can help.
Volterony