0

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,  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

3
  • so you want the amount + 200? and your example dictates 500+200=2500? Whats going on? Commented Dec 1, 2009 at 11:47
  • Nicky: 200? Reads 2000 to me. Commented Dec 1, 2009 at 11:54
  • don't forget to tick the answer that helped you resolve your issue! :) hint hint! Commented Dec 1, 2009 at 18:01

2 Answers 2

2

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");
Sign up to request clarification or add additional context in comments.

Comments

0
<?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");
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.