如何知道特定的山羊出生的山羊数量

时间:2015-10-09 01:16:48

标签: php mysql

我想知道她山羊生下了多少孩子。下面是我的代码,它没有给我我想要的东西所以有人应该帮助我,请。

<?php

include("db.php");



$query = "SELECT mothername, COUNT(goatid) FROM goats GROUP BY     mothername"; 

$result = mysql_query($query) or die(mysql_error());

// Print out result
while($row = mysql_fetch_array($result)){
echo "There are ". $row['COUNT(goatid)'] ." ". $row['mothername'] ."   Children Goat(s).";
echo "<br/>";
}


?>

1 个答案:

答案 0 :(得分:1)

我终于得到了逻辑。这是它

include("db.php");



$query = "SELECT mothername, COUNT(goatid) FROM goats GROUP BY mothername"; 

$result = mysql_query($query) or die(mysql_error());

// Print out result
while($row = mysql_fetch_array($result)){
echo  $row['mothername'] ." has ". $row['COUNT(goatid)'] ." Kid(s).";
echo "<br/>";
}


?>