How do I create a php code for mysql to do the fallowing?
if active = 1 to do current amount + 2000
id, eid, amount, apply 1, apply 2, apply 3, active
1 1788 500 NULL NULL NULL 1
2 1956 1000 NULL NULL NULL 1
3 2035 1500 NULL NULL NULL 1
And the output to be like this nothing else to change.
id, eid, amount, apply 1, apply 2, apply 3开发者_如何学Go, active
1 1788 2500 NULL NULL NULL 1
2 1956 3000 NULL NULL NULL 1
3 2035 3500 NULL NULL NULL 1
Thanks in front for people who will help
The SQL query is as follows:
UPDATE tablename SET amount=amount+2000 WHERE active=1;
How you execute this in PHP depends on which database driver you're using.
For example, using mysqli
:
<?php
$link = mysqli_init();
mysql_real_connect($link, $host, $username, $password, $db_name);
mysqli_query($link, "UPDATE tablename SET amount=amount+2000 WHERE active=1");
<?php
$host = "host";
$username= "username";
$password= "password";
$db_name= "db_name";
$link = mysql_connect($host, $username, $password);
mysql_select_db($db_name, $link);
mysql_query("UPDATE tablename SET amount=amount+2000 WHERE active=1");
?>
精彩评论