I get a very strange result from my database query, I was hoping that someone might notice what I missed.
heres my table with some data examples:
feeling_id country date feeling digit
25 australia 2011-02-21 bad 1
26 australia 2011-02-21 bad 0
8 france 2011-02-21 better 1
im trying to calculate how much of each country is in the database, and how many of them have the number 1. Thus, the above data will give:
Australia with the number 1 = 1
australia rows in database = 2
france with the number 1 = 1
france rows in database = 1
here is the code
<?php
include ('mysqli_connect.php');
$countries = array('united states','canada','united kingdom');
$r = array();
foreach($countries as $country){
$r[$country] = mysqli_query($dbc,"SELECT * FROM feelings WHERE country = '$country' AND digit='1'");
while($row = mysqli_fetch_array($r[$country], MYSQLI_ASSOC)){
$rowCount = mysqli_num_rows($r[$country]);
}
$r[$country] = mysqli_query($dbc,"SELECT * FROM feelings WHERE country = '$country'");
while($row = mysqli_fetch_array($r[$country], MYSQLI_ASSOC)){
$rowCount2 = mysqli_num_rows($r[$country]);
}
echo $country . '=' . $rowCount . '<br />';
echo $country . '=' . $rowCount2 . '<br />';
}
?>
I get the following result when there are only two canada lines in the database, none of them have the number 1 ???
with the number 1 = 13
combined state rows in database = 17
Canada with the number 1 = 13
canada rows in database = 2
united kingdom with the number 1 = 4
united kingdom rows in database = 4
the answer should say: "Canada with the number 1 = 0"Canada with a digit from 1 answer seems to copy the combined state digit with 1 result.
Can anyone see where I made a mistake?
Thanks alsweeet