开发者

adding up tables in mysql

开发者 https://www.devze.com 2023-03-09 15:34 出处:网络
Hello I have a table with 11 in and about 7 tables with 1 in Each has 2 column username and clicks. The problem is that i have to add up all the clicks were username = username Is there anyway i can

Hello I have a table with 11 in and about 7 tables with 1 in

Each has 2 column username and clicks. The problem is that i have to add up all the clicks were username = username Is there anyway i can do that ?

I'm using

$result1233 = mysql_query("SELECT * FROM urls_non_loggedin WHERE username='$_SESSION[username]'");

$num_row3s = mysql_num_rows($result1233);

Bu开发者_运维知识库t I want to add up all the clicks "the column name " where username = $_SESSION[username]

If you get what I mean ?

So there is a table with 2 columns clicks and username I want to grab all the numbers in clicks and add them up were username = usersname


You can use the SQL SUM operator. Like this:

SELECT username, SUM(clicks) As number_of_clicks FROM urls_non_loggedin WHERE username='$_SESSION[username]' GROUP BY username

Although you should be careful from passing variables into your queries that you have not sanitized.

EDIT: I replaced * with username in accordance to the comment from the moderator

0

精彩评论

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