ririe44 Posted February 25, 2009 Share Posted February 25, 2009 So, I've read up on a couple things on updating multiple fields, but I wanted to run this by you... Can you do this so it's under one query? $query = (UPDATE...) AND (UPDATE...) AND, etc? What would be the cleanest way to do this? I have 36 fields being updated. Thanks! Link to comment https://forums.phpfreaks.com/topic/146912-update-multiple-fields/ Share on other sites More sharing options...
premiso Posted February 25, 2009 Share Posted February 25, 2009 UPDATE set col1 = 'someval', col2 = 'someval' WHERE somecol = 'someval' Link to comment https://forums.phpfreaks.com/topic/146912-update-multiple-fields/#findComment-771288 Share on other sites More sharing options...
ririe44 Posted February 25, 2009 Author Share Posted February 25, 2009 I see how that'd work, but in my case every field will be different... For example... ("UPDATE `$tbl_name` SET `amount` = '$budg_mustang' WHERE `sub_category` = 'Mustang'"); ("UPDATE `$tbl_name` SET `amount` = '$budg_vulcan' WHERE `sub_category` = 'Vulcan'"); All 36 of them... Link to comment https://forums.phpfreaks.com/topic/146912-update-multiple-fields/#findComment-771291 Share on other sites More sharing options...
ririe44 Posted February 25, 2009 Author Share Posted February 25, 2009 Any thoughts anyone? If I have to do individual queries for each... would I just do something similar?: $query_mustang = ("UPDATE `$tbl_name` SET `amount` = '$budg_mustang' WHERE `sub_category` = 'Mustang'"); $query_vulcan = ("UPDATE `$tbl_name` SET `amount` = '$budg_vulcan' WHERE `sub_category` = 'Vulcan'"); if (mysql_query($query_mustang, $query_vulcan)) { echo "Your budget has been updated! <br> Would you like to make another modification? <a href='budg_retrieve.php'>Yes</a>"; }else { die(mysql_error()); } Link to comment https://forums.phpfreaks.com/topic/146912-update-multiple-fields/#findComment-771393 Share on other sites More sharing options...
sasa Posted February 25, 2009 Share Posted February 25, 2009 UPDATE `$tbl_name` SET `amount` = CASE `sub_category` WHEN 'Mustang' THEN '$budg_mustang' WHEN 'Vulcan' THEN '$budg_vulcan' ... ELSE `amount` END Link to comment https://forums.phpfreaks.com/topic/146912-update-multiple-fields/#findComment-771412 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.