About PHP Processing table statistics function

Source: Internet
Author: User
I do a statistical page effect is

The database tables that are created are

Solve how to use PHP implementation, thank you!


Reply to discussion (solution)

A SQL command can be completed

@xuzuning
The Great God ... I'm afraid not!

Yes, I can.

I'm a rookie! Completely retwist!

Select Class, COUNT (*) as number, sum (score) as total number, sum (if (Result valid = ' yes ', 1,0) as effective number, sum (if (the result is valid = ' yes ', score, 0) as effective score ...

Don't write, you lazy use, I do not want to type

@xuzuning sum (if (whether the score is valid = ' yes ', 1,0)) This is not an effective number.

Try the group by and have

@xuzuning @jmy454157571

SQL is right, but PHP loop output is not
$mysqli =new mysqli ("localhost", "root", "" "," car_insure ");
$mysqli->set_charset ("UTF8");
if ($mysqli->connect_error) {
Die ("Connection failed". $mysqli->conect_error);
}
$sql = "Select T3.*,t4.totalnum as ' invalid total number of people ', T4.totalscore as ' invalid score ' from
(Select T1.class_ as ' class ', t1.totalnum as ' total number ', T1.totalscore as ' total score ', t2.totalnum as ' effective total number ', t2.totalscore as ' effective total score ' from (select Class_,count (id_) as Totalnum,sum (score_) as Totalscore from score Group by Class_) as T1 LEFT join (SELECT class _,count (id_) as Totalnum,sum (score_) as Totalscore from score Group by Class_,flag_ have flag_= ' is ') as T2 on t1.class_=t 2.class_)
as T3
Left joins (select Class_,count (id_) as Totalnum,sum (score_) as Totalscore from score Group by Class_,flag_ have flag_= ' no ') as T4
on T3. ' Class ' =t4.class_ '
$res = $mysqli->query ($sql);

if ($res) {
echo "2222";
}else{
echo "1111";
}
$mysqli->close ();
?>
Output is 1111
This is what happened, $res didn't get the value Ah! Trouble to see where the problem

SQL statements are the right query in MySQL.

  • 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.