How to combine multiple Updates

Codes here !

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 23
Joined: Sun Jan 01, 2012 4:37 am

Sat Mar 02, 2013 8:44 am

Code: Select all

$rem1 = "UPDATE `subjecttaken` SET `Remarks`= 'FAILED' WHERE `Grade` < '75' and `SNum`='$SNum' ";
$rem2 = "UPDATE `subjecttaken` SET `Remarks`= 'PASSED' WHERE `Grade` > '75'  and `SNum`='$SNum' ";
$rem3 = "UPDATE `subjecttaken` SET `Remarks`= 'No Grade' WHERE `Grade` = ''  and `SNum`='$SNum' ";
$rem4 = "UPDATE `subjecttaken` SET `Remarks`= 'PASSED' WHERE `Grade` = '75'  and `SNum`='$SNum' ";
$rem5 = "UPDATE `subjecttaken` SET `Remarks`= 'INCOMPLETE' WHERE `Grade` = 'INC'  and `SNum`='$SNum' ";
My problem about this is it loads too long so im guessing its because of i have lots to update?
There is a possibility of combing all of them into one right? That will also lessen the loading?

php-forum Fan User
php-forum Fan User
Posts: 974
Joined: Mon Oct 01, 2012 12:32 pm

Thu Mar 07, 2013 2:02 pm

you should not be using those mysql functions; you should be using mysqli at the very least, or preferably PDO. The proper way to do what you're trying to do would be with prepared statements. There is a great short video on getting started with PDO and prepared statements at ... o-examples The video runs just shy of 11 minutes, but will save you hours in studying. With prepared statements, you build the query once in prepare, and then execute it with an array of values to update. it's good, quick, and a lot more secure.

Post Reply