So lets say we have a large inventory of items(5000+) held in a database. Now lets say 2000 of these items do something different than the last. Which of the following ways is more efficient? Or maybe you have your own suggestion .
Store individual code bits in the DB, then pull and run
<?php
$item_id = $_GET['item_id'];
$findItem = $db->query("select `code` from `items` where `item_id` = '{$item_id}'");
if ($findItem) {
$itemCode = $db->fetch($findItem);
eval ($itemCode['code']);
}
?>
Store all item codes in an inventory script
<?php
$item_id = $_GET['item_id'];
switch ($item_id){
case 123:
//do this
break;
case 124:
//do this
break;
//continuing on for my 2000 item list
}
?>
I know the first one looks more efficient, but I've heard its not good to use eval :S