开发者

Addition with multiple MySQL entries

I have 开发者_JAVA技巧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!


SELECT L1+L2+L3+L4 AS LTOTAL FROM table WHERE ID = '$sID'


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

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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜