我使用以下代码:
$query = "SELECT ves, COUNT(ves) FROM books GROUP BY ves";
$result = mysql_query($query) or die(mysql_error());
// Print out result
while($row = mysql_fetch_array($result)){
echo "There are ". $row['COUNT(ves)'] ." books";
echo "<br />";
}
我给了我以下结果:
有176本书。 共有5本书。
第一行结果是db上的总书。 我只需要获得与ves colum值相对应的第二个结果,我该如何得到它?
提前谢谢你。 NPinelo
答案 0 :(得分:0)
使用var(在本例中为$i
)来控制你在第二行的时间
$query = "SELECT ves, COUNT(ves) FROM books GROUP BY ves";
$result = mysql_query($query) or die(mysql_error());
// Print out result
$i = 1;
while($row = mysql_fetch_array($result)){
if($i == 2) {
echo "There are ". $row['COUNT(ves)'] ." books";
echo "<br />";
}
$i++;
}
答案 1 :(得分:0)
试试这个例子:
$query = "SELECT ves, COUNT(ves) as ves_count FROM books GROUP BY ves";
$result = mysql_query($query) or die(mysql_error());
// Print out result
while($row = mysql_fetch_array($result)){
echo "There are ". $row['ves_count'] ." books";
echo "<br />";
}
答案 2 :(得分:0)
感谢所有有益的思想,以下代码是我最终需要的工作:
$query = "SELECT ven, COUNT(ven) FROM books WHERE ven='en'";
$result = mysql_query($query) or die(mysql_error());
// Print out result
while($row = mysql_fetch_array($result)){
echo "Here are ". $row['COUNT(ven)'] ." books";
echo "<br />";
}