I finishing up work on a site and burning the candle at both ends. I can seem to fix this simple problem. I have been struggling with way too long with not enough sleep.
I pulling data from a third-party site and trying to "cache" the data so I do not have to keep calling the API. I am simply calling it and storing the results in an array. I then write that array to a file and include it into my snippet.
It works fine when I call it once. But when I call multiple times on the page it fails. I can call it uncached but it will not update when the url parameter changes. At first I had a function and I thought that was causing the problem, so I re-wrote it, still no luck. Any ideas?
displayCategory (snippet)
<?php
$catId = $_GET['ProductTypeID'];
$file = 'assets/files/category_list.php';
if (file_exists($file)) {
$output = include_once $file;
} else {
$output = 'File not found at: '.$file;
}
$searched = array('ProductTypeId'=>$catId);
foreach ($myArray as $key => $value) {
$exists = true;
foreach ($searched as $skey => $svalue) {
$exists = ($exists && IsSet($myArray[$key][$skey]) && $myArray[$key][$skey] == $svalue);
}
if ($exists) {
$output = $myArray[$key]['Name'];
}
}
return $output;
?>
category_list.php (the included array)
<?php
$myArray = array (
0 =>
array (
'ProductTypeId' => 9,
'Name' => 'Fruits',
'ProductCount' => 109,
),
1 =>
array (
'ProductTypeId' => 46,
'Name' => 'Vegetables',
'ProductCount' => 100,
),
2 =>
array (
'ProductTypeId' => 71,
'Name' => 'Grains',
'ProductCount' => 10,
),
); ?>