This is for adding images, categories and comments from an email to a photo gallery I'm working on.
I'm pulling the first two found category names out of an email message body and need to assign the category id to $cat variable for insertion into DB.
I have it working fine hardcoded, but would like to make it dynamic so changes to category names will cascade throughout.
The switch statement I'd like to change:
Hardcoded:
foreach($foundKeywords as $key => $value) {
if($key<=1){
switch($value)
{
case 'family':
$cat='3';
break;
case 'friends';
$cat='4';
break;
case 'fun';
$cat='6';
break;
case 'places';
$cat='5';
break;
case 'general';
$cat='2';
break;
case 'henry';
$cat='7';
break;
default;
$cat='2';
}
I'd like to pull the categories from a MySQL table and do it this way:
$res = mysql_query('SELECT * FROM gallery_category');
$cat_switch_list = "";
while($row = mysql_fetch_array($res)){
$cat_switch_list .= "case '".$row[1]."':
$cat = ".$row[0].";
break;";
}
//////////////////////
foreach($foundKeywords as $key => $value) {
if($key<=1){
switch($value)
{
echo $cat_switch_list;
default:
$cat='1';
}
In theory, I believe this should work, but something is not right.
Any suggestions?