1

I have a table and in the table it has several fields that are named L1, L2, L3, and L4. Those fields are just numbers. So, what should the script look like to have L1 through L4 added together where ID='$sID'? Say L1 and L3 have a value of 2 and L2 and L4 have a value of 1 for that user. I would like the page to say '6' so the user can see the total.

Thanks!

3 Answers 3

2
SELECT L1+L2+L3+L4 AS LTOTAL FROM table WHERE ID = '$sID'
Sign up to request clarification or add additional context in comments.

Comments

1
SELECT L1+L2+L3+L4 FROM <tablename> WHERE ID=?

and then pass in your ID using the normal mysql prepared statement functions in PHP.

Comments

0

It sounds like you are making the query in PHP and then executing it with a mysql_query(). If that is the case, this line should be the query you are looking for.

$query = "SELECT (L! + L2 + L3 + L4) FROM tableName WHERE id = {$sID}";

php mysql selects have a few functions associated with them, if you are unfamiliar with it, I would suggest looking into it here: http://www.w3schools.com/php/php_mysql_select.asp

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.