Forum Moderators: coopster
I have a database of 1000 widgets with name, color, description, id, etc. The database is updated weekly. What I'd like to do is output all this information once a week from MySQL into a php array instead of having visitors calling mysql for the information when accessing pages.
$widgetColor = array("red","green","blue","black","white");
$widgetname = array("one","two","three","four","five");
etc.
So if i went to the page example.com/widgets/three, i'd get the color blue to describe it. The thing is, to get the location for the color, I have to use a for loop to fin the number of the location.
$name = $_GET['name'];
for($i=0, $i<=1000; $i++)
{
if($widgetname[$i] == $name)
$color = $widgetColor[$i];
}
This still seems inefficient but i think better than using MySQL. Good idea or not? Anyway to make this more efficient?
$widgets = array("one"=>"red", "two"=>"green", [etc.]); Also, recent versions of MySQL have query caching options for repeated identical queries on an unchanged table. So such queries should not be a bottleneck in your app.