2
Good evening everyone. I have little experience in programming. I apologize if I am not very clear on the question.
I have a Mysql database (phpmyadmin) with a table named "my table" having one of the fields named "value". I need to add the "value" field of all rows in the table.
To count the amount of data worked when I used the following excerpt:
$select = $pdo->query("SELECT * FROM minha_tabela")->fetchAll();
// atribuindo a quantidade de linhas retornadas
$count = count($select);
// imprimindo o resultado
print $count;
Now I have to add up and I don’t know how to write the program. I am using PDO programming. Thank you very much.
If it’s just a count, use
SELECT COUNT(*) FROM minha_tabela
instead of thiscount($select)
, so you have a result line with the value. This is what you’ve done by moving the entire table from Mysql to PHP just to get a count, which is unthinkable in a normal application (unless you’re going to use all the data right away).– Bacco