본문 바로가기

SQL/MYSQL

php mysql 여러행 한번에 업데이트하기


php mysql 여러행 한번에 업데이트하기

mysql update multiple rows mysql 한번에 여러행 업데이트 하기

        //하나씩 업데이트
	$sql1 = "update MAIN set CONTENTS='$menu_name1'   where MENU_NAME = 'menu_name1'  ";
	$sql2 = "update MAIN set CONTENTS='$menu_name2'   where MENU_NAME = 'menu_name2'  ";
	$sql3 = "update MAIN set CONTENTS='$menu_name3'   where MENU_NAME = 'menu_name3'  ";
	$sql4 = "update MAIN set CONTENTS='$menu_name4'   where MENU_NAME = 'menu_name4'  ";
	$sql5 = "update MAIN set CONTENTS='$menu_name5'   where MENU_NAME = 'menu_name5'  ";
       
	$res1 = mysql_query($sql1,$connect);
	$res2 = mysql_query($sql2,$connect);
	$res3 = mysql_query($sql3,$connect);
	$res4 = mysql_query($sql4,$connect);
	$res5 = mysql_query($sql5,$connect);



        //한번에 업데이트

			$sql1 = "	UPDATE MAIN
							SET CONTENTS = CASE MENU_NAME
								WHEN 'menu_name1' THEN '$menu_name1'
								WHEN 'menu_name2' THEN '$menu_name2' 
								WHEN 'menu_name3' THEN '$menu_name3'
								WHEN 'menu_name4' THEN '$menu_name4' 
								WHEN 'menu_name5' THEN '$menu_name5' 
							END
						WHERE MENU_NAME BETWEEN 'menu_name1' AND 'menu_name5'
			";

                       $res1 = mysql_query($sql1,$connect);