tufanv Expert Licensed User Longtime User Sep 12, 2016 #1 Hello I use a php on server side to retrieve to my b4a app. I have in my php code following : Code: Copy $q = "SELECT * FROM tahmincilerintahminleri where username= '".$user."' and Tuttu='2' "; $r = mysql_query($q); $a = mysql_fetch_assoc($r); $tutmayankar='0'; while(($row = mysql_fetch_assoc($r))) { $tutmayankar = $tutmayankar + $a['guven']; Here I want to get the sum of the column "guven" for each row with $tutmayankar.. I use while as above. But there is a problem with this. I get the wrong result. I think i am making a mistake in the code. ( I tested it , I add a new row to my sql database with guven column =4 and as a result $tutmayankar increases for 3 for example. Can you see any problem with the code ? TY
Hello I use a php on server side to retrieve to my b4a app. I have in my php code following : Code: Copy $q = "SELECT * FROM tahmincilerintahminleri where username= '".$user."' and Tuttu='2' "; $r = mysql_query($q); $a = mysql_fetch_assoc($r); $tutmayankar='0'; while(($row = mysql_fetch_assoc($r))) { $tutmayankar = $tutmayankar + $a['guven']; Here I want to get the sum of the column "guven" for each row with $tutmayankar.. I use while as above. But there is a problem with this. I get the wrong result. I think i am making a mistake in the code. ( I tested it , I add a new row to my sql database with guven column =4 and as a result $tutmayankar increases for 3 for example. Can you see any problem with the code ? TY
DonManfred Expert Licensed User Longtime User Sep 12, 2016 #2 you are dfining a string Code: Copy $tutmayankar=0; while(($row = mysql_fetch_assoc($r))) { $tutmayankar += $row['guven']; Upvote 0
you are dfining a string Code: Copy $tutmayankar=0; while(($row = mysql_fetch_assoc($r))) { $tutmayankar += $row['guven'];
tufanv Expert Licensed User Longtime User Sep 12, 2016 #3 Yes ! Thanks very Much. That's fixed it ! Upvote 0
LucaMs Expert Licensed User Longtime User Sep 12, 2016 #4 You can use a simple function, instead of that loop: http://www.w3schools.com/sql/sql_func_sum.asp (you can add a Where clause, which is missing in that page, of course) Upvote 0
You can use a simple function, instead of that loop: http://www.w3schools.com/sql/sql_func_sum.asp (you can add a Where clause, which is missing in that page, of course)
DonManfred Expert Licensed User Longtime User Sep 12, 2016 #5 LucaMs said: you can add a Where clause, which is missing in that page, of course Click to expand... No, it is NOT missing tufanv said: $q = "SELECT * FROM tahmincilerintahminleri where username= '".$user."' and Tuttu='2' "; Click to expand... Upvote 0
LucaMs said: you can add a Where clause, which is missing in that page, of course Click to expand... No, it is NOT missing tufanv said: $q = "SELECT * FROM tahmincilerintahminleri where username= '".$user."' and Tuttu='2' "; Click to expand...
LucaMs Expert Licensed User Longtime User Sep 12, 2016 #6 DonManfred said: No, it is NOT missing Click to expand... I meant it is missing in the page at link I posted Upvote 0
DonManfred said: No, it is NOT missing Click to expand... I meant it is missing in the page at link I posted