How does php output table content quickly and efficiently?

Source: Internet
Author: User
Php outputs table content quickly and efficiently. At the end of this post, phpcainiao edited php on 2013-09-0612: 03: 08 to output table content quickly and efficiently. For example, I now have a test table. Id, fenlei, and mc are represented respectively, id, automatic growth, fenlei, and mc in the participating regions. the specific selection parameter id & nbsp; & how php outputs table content is quick and efficient.

This post was last edited by phpcainiao at 12:03:08

Php outputs table content quickly and efficiently.

For example, I now have a test table.
There are IDs, fenlei, mc
Id, automatic growth,
Fenlei, participating regions
Mc, specific selection parameters
Id fenlei mc
1 Beijing health care
2 Shanghai health care
3. good service in Shanghai
4 Tianjin health care
5. good service in Tianjin
6. good service in Beijing
7 Shanghai health care
8. good service in Shanghai

I want to make a statistics on this table .. Use the program to output the following table.

I want to separate statistics


Share:


------ Solution --------------------
select a.fenlei, count(*), count(*)/(select count(*) from test)*100 as percentage, constitute
from test a, (select fenlei, group_concat(mc,',',cnt) as constitute from
(select fenlei, mc, count(*) as cnt from test group by 1,2) t group by 1) t1
where a.fenlei=t1.fenlei
group by 1

Execute this SQL command to obtain such data
Array
(
[0] => Array
(
[Fenlei] => Beijing
[Count (*)] => 2
[Percentage] = & gt; 25.0000
[Constitute] => good service, 1. good hygiene, 1
)

[1] => Array
(
[Fenlei] => Shanghai
[Count (*)] => 4
[Percentage] = & gt; 50.0000
[Constitute] => good service, 2, good hygiene, 2
)

[2] => Array
(
[Fenlei] => Tianjin
[Count (*)] => 2
[Percentage] = & gt; 25.0000
[Constitute] => good service, 1. good hygiene, 1
)

)
The constitute column must be processed during output.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.