sum and count

Posted under » PHP on 14 March 2022

I'm a noob in excel and the only thing I use is the sum function.

In php it may look like this.

if ($result = $dbhandle -> query("SELECT * FROM question")) {

while($row = mysqli_fetch_array($result)) {
    $sum += $row['value'];
    }
    echo $sum."
"; } $dbhandle -> close();

This is the same with python django count.

If you want to just increment or +1 use ++ just like this example.

For arrays, you can do this in Python

salah = [1,2,1,4,100]

for cat in salah:
    print(sum(salah))

Or you can append to the array and do a len if want to count the value of 1s.

 betul = []
 for cat in x["stage107f"]:
 	kuching = cat["correctness"]
	if kuching == 1 :
	betul.append(1) 
 print(len(betul))


web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS data