Table1 有 3 列,如下所示
id | user | place
1 A England
2 B USA
3 C England
<?php
$sql=("SELECT id FROM table1 WHERE place='England'");
$query1=mysqli_query($con, $sql);
$query1num=mysqli_num_rows($query1);
if($query1num !=0){
while($row1=mysqli_fetch_assoc($query1){
$id=$row1['id'];
}
}
?>
//using above query i got two id who's from England
如何从表 2 中获取其中有多少(计数)具有 php(其中 uid='$id')以及其中有多少(计数)具有 java(其中 uid='$id')
表 2 有 3 列类似
(ID、UID、字段) 和 3 个条目是值是
(1, 1, 菲律宾比索)
(2, 2, 爪哇)
(3, 3, 菲律宾比索)
拜托,我是新手(学习 php 和 sql)。
根据我的理解,你可以试试这个:
select field, count(*)
from table2 where id in (SELECT id FROM table1 WHERE place like 'england')
group by field;
你可以在这里看到输出:SQlFiddle
试试这个-
<?php
$sql=("SELECT field, count(*) FROM table2 GROUP BY field");
$query1=mysqli_query($con, $sql);
$query1num=mysqli_num_rows($query1);
if($query1num > 0){
while($row1=mysqli_fetch_assoc($query1){
echo $row1['field']." = ".$row1['count(*)'];
}
}
?>
试试这个,我希望它会起作用
while($row1=mysqli_fetch_assoc($query1)
{
$id[]=$row1['id'];
}
$count=array_count($id);
echo $count;