Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

How to combine multiple Updates

Codes here !

Moderators: macek, egami, gesf

How to combine multiple Updates

Postby ShadowSkill » Sat Mar 02, 2013 8:44 am

Code: Select all
$rem1 = "UPDATE `subjecttaken` SET `Remarks`= 'FAILED' WHERE `Grade` < '75' and `SNum`='$SNum' ";
mysql_query($rem1);
$rem2 = "UPDATE `subjecttaken` SET `Remarks`= 'PASSED' WHERE `Grade` > '75'  and `SNum`='$SNum' ";
mysql_query($rem2);
$rem3 = "UPDATE `subjecttaken` SET `Remarks`= 'No Grade' WHERE `Grade` = ''  and `SNum`='$SNum' ";
mysql_query($rem3);
$rem4 = "UPDATE `subjecttaken` SET `Remarks`= 'PASSED' WHERE `Grade` = '75'  and `SNum`='$SNum' ";
mysql_query($rem4);
$rem5 = "UPDATE `subjecttaken` SET `Remarks`= 'INCOMPLETE' WHERE `Grade` = 'INC'  and `SNum`='$SNum' ";
mysql_query($rem5);


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?
ShadowSkill
New php-forum User
New php-forum User
 
Posts: 23
Joined: Sun Jan 01, 2012 4:37 am

Re: How to combine multiple Updates

Postby seandisanti » 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 http://jream.com/learning/videos/php-oo ... 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.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 4 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.