Hi all,
Can anyone tell me how to make the following script more concise?
There must be a better way than what i have so far.
Cheers,
camcim
Can anyone tell me how to make the following script more concise?
There must be a better way than what i have so far.
Code:
if($update_cat){
echo "$total<br>";
if($category_1){
$update_1 ="UPDATE company_categories SET category_id='$category_1' WHERE comp_cat_id = '$comp_cat_id1'";
$result1 = mysql_query($update_1);
}
if($category_2){
$update_2 ="UPDATE company_categories SET category_id='$category_2' WHERE comp_cat_id = '$comp_cat_id2'";
$result2 = mysql_query($update_2);
}
if($category_3){
echo "$category_3<br>";
$update_3 ="UPDATE company_categories SET category_id='$category_3' WHERE comp_cat_id = '$comp_cat_id3'";
$result3 = mysql_query($update_3);
} else if(!$result3 && $category_3){
$update_3 ="INSERT INTO company_categories (comp_cat_id,company_id,category_id) VALUES (NULL,'$company_id3','$category_3')";
$result3 = mysql_query($update_3);
}
if($category_4){
$update_4 ="UPDATE company_categories SET category_id='$category_4' WHERE comp_cat_id = '$comp_cat_id4'";
$result4 = mysql_query($update_4);
}
if($category_5){
$update_5 ="UPDATE company_categories SET category_id='$category_5' WHERE comp_cat_id = '$comp_cat_id5'";
$result5 = mysql_query($update_5);
}
if($category_6){
$update_6 ="UPDATE company_categories SET category_id='$category_6' WHERE comp_cat_id = '$comp_cat_id6'";
$result6 = mysql_query($update_6);
}
if($category_7){
$update_7 ="UPDATE company_categories SET category_id='$category_7' WHERE comp_cat_id = '$comp_cat_id7'";
$result7 = mysql_query($update_7);
}
if($category_8){
$update_8 ="UPDATE company_categories SET category_id='$category_8' WHERE comp_cat_id = '$comp_cat_id8'";
$result8 = mysql_query($update_8);
}
if($category_9){
$update_9 ="UPDATE company_categories SET category_id='$category_9' WHERE comp_cat_id = '$comp_cat_id9'";
$result9 = mysql_query($update_9);
}
if($category_10){
$update_10 ="UPDATE company_categories SET category_id='$category_10' WHERE comp_cat_id = '$comp_cat_id10'";
$result10 = mysql_query($update_10);
}
Cheers,
camcim