商品省份归属统计,36行代码运行太慢,如何简化提速?

商品归属省份统计,下面代码优化
  • $arrCountP1= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =1  " );
    $arrCountP2= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =2  " );
    $arrCountP3= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =3  " );
    $arrCountP4= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =4  " );
    $arrCountP5= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =5  " );
    $arrCountP6= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =6  " );
    $arrCountP7= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =7  " );
    $arrCountP8= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =8  " );
    $arrCountP9= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =9  " );
    $arrCountP10= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =10  " );
    $arrCountP11= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =11  " );
    $arrCountP12= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =12  " );
    $arrCountP13= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =13  " );
    $arrCountP14= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =14  " );
    $arrCountP15= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =15  " );
    $arrCountP16= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =16  " );
    $arrCountP17= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =17  " );
    $arrCountP18= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =18  " );
    $arrCountP19= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =19  " );
    $arrCountP20= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =20  " );
    $arrCountP21= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =21  " );
    $arrCountP22= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =22  " );
    $arrCountP23= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =23  " );
    $arrCountP24= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =24  " );
    $arrCountP25= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =25  " );
    $arrCountP26= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =26  " );
    $arrCountP27= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =27  " );
    $arrCountP28= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =28  " );
    $arrCountP29= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =29  " );
    $arrCountP30= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =30  " );
    $arrCountP31= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =31  " );
    $arrCountP32= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =32  " );
    $arrCountP33= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =33  " );
    $arrCountP34= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =34  " );
    $arrCountP35= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =35  " );
    $arrCountP36= db_factory::get_count ( "select count(*) from " . TABLEPRE . "service where cat = '$ky' and province =36  " );
    

一个sql就能同时取出所有省份的统计数据,干哈分这么多?

select province, count(*) ct from " . TABLEPRE . "service where cat = '$ky' group by province

从数据库取数据不是你这么取的啊,哪有查一个列表的数据时,一个sql只查一个值的啊,你直接一个查询,然后循环输出结果不就好了?
比如这篇教程里的例子,就是一个sql取了3行数据