Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make script more concise

Status
Not open for further replies.

camcim

Programmer
Jan 25, 2003
20
0
0
US
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.
Code:
if($update_cat){
echo &quot;$total<br>&quot;;
if($category_1){
$update_1 =&quot;UPDATE company_categories SET category_id='$category_1' WHERE comp_cat_id = '$comp_cat_id1'&quot;;
$result1 = mysql_query($update_1);
} 
if($category_2){
$update_2 =&quot;UPDATE company_categories SET category_id='$category_2' WHERE comp_cat_id = '$comp_cat_id2'&quot;;
$result2 = mysql_query($update_2);
} 
if($category_3){
echo &quot;$category_3<br>&quot;;
$update_3 =&quot;UPDATE company_categories SET category_id='$category_3' WHERE comp_cat_id = '$comp_cat_id3'&quot;;
$result3 = mysql_query($update_3);
} else if(!$result3 && $category_3){
$update_3 =&quot;INSERT INTO company_categories (comp_cat_id,company_id,category_id) VALUES (NULL,'$company_id3','$category_3')&quot;;
$result3 = mysql_query($update_3);
}
if($category_4){
$update_4 =&quot;UPDATE company_categories SET category_id='$category_4' WHERE comp_cat_id = '$comp_cat_id4'&quot;;
$result4 = mysql_query($update_4);
}
if($category_5){
$update_5 =&quot;UPDATE company_categories SET category_id='$category_5' WHERE comp_cat_id = '$comp_cat_id5'&quot;;
$result5 = mysql_query($update_5);
}
if($category_6){
$update_6 =&quot;UPDATE company_categories SET category_id='$category_6' WHERE comp_cat_id = '$comp_cat_id6'&quot;;
$result6 = mysql_query($update_6);
}
if($category_7){
$update_7 =&quot;UPDATE company_categories SET category_id='$category_7' WHERE comp_cat_id = '$comp_cat_id7'&quot;;
$result7 = mysql_query($update_7);
}
if($category_8){
$update_8 =&quot;UPDATE company_categories SET category_id='$category_8' WHERE comp_cat_id = '$comp_cat_id8'&quot;;
$result8 = mysql_query($update_8);
}
if($category_9){
$update_9 =&quot;UPDATE company_categories SET category_id='$category_9' WHERE comp_cat_id = '$comp_cat_id9'&quot;;
$result9 = mysql_query($update_9);
}
if($category_10){
$update_10 =&quot;UPDATE company_categories SET category_id='$category_10' WHERE comp_cat_id = '$comp_cat_id10'&quot;;
$result10 = mysql_query($update_10);
}

Cheers,
camcim
 
what are you trying to achieve ? more code or info would help. ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Why does the code for [tt]$category_3[/tt] differ from the others? //Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top