I am trying to select ALL the values in one of the columns in my db where a certain condition is met, but I only seem to get 1 result and not an array of results, any ideas? see below:
<?php
$query_c1 = "SELECT main FROM orders WHERE dh_code= 'my cd'";
$db_charity = dbQuery($query_c1);
while($fetch_charity=mysql_fetch_array($db_charity)){
echo $fetch_charity[0];
}
?>
it is decimal(15,2) - they are numbers like 29.95. I want to take all these numbers where a specific column equals ‘my cd’. Then I want to calculate the total - that is why I am using array_sum, but I dont think its in the right place…
mysql_fetch_array() only returns an array of one of the rows, what you want is the sum of all of the rows. So you’d have to loop all rows first and store the values in an array and array_sum that one, or keep a variable and add the price to it for every row. So, you could either do this –
– but actually you should not use either of those, but rather use the suggestion Rudy (r937) just suggested; it’s ~far~ better than either of the solutions above