ต้องใช้ count อ่ะครับ
เช่นจะนับว่ามีเพศชายกี่คนก็ select count(*) from bmi_db where sex='male'
ถ้าจะหาจำนวนเพศชายที่อ้วนก็ select count(*) from bmi_db where sex='male' where bmi>เกณฑ์
จำนวนผู้ชาย = select count(*) from bmi_db where sex='male'
ผู้ชายที่อ้วน = select count(*) from bmi_db where sex='male' where bmi>25
ผู้ชายที่ผอม = select count(*) from bmi_db where sex='male' where bmi<20
ผู้ชายปกติ = select count(*) from bmi_db where sex='male' where (bmi between 20 and 24.9)
$connect=mysql_connect($host, $user, $pass) or die(mysql_error());
mysql_select_db($dbname1) or die(mysql_error());
$sql = select count(*) from bmi_db where sex='male'
$sql = select count(*) from bmi_db where sex='male' where bmi>25
$sql = select count(*) from bmi_db where sex='male' where bmi<20
$sql = select count(*) from bmi_db where sex='male' where (bmi between 20 and 24.9)
ตรง sql ใส่ " ด้วยนะ
$sql = " select count(*) from bmi_db where sex='male' ";
Date :
2010-07-19 15:55:43
By :
heng
No. 20
Guest
มันขึ้นว่า
No database selected คะ
แล้วจะให้มันแสดงตามที่เราเลือกได้ยังไงคะ รบกวนหน่อยคะพี่
Date :
2010-07-19 16:56:13
By :
ยี
No. 21
Guest
mysql_select_db($dbname1) or die(mysql_error()); ผิด
$dbname1 ไม่มี 1 นะ
mysql_select_db($dbname) or die(mysql_error());
Date :
2010-07-19 17:21:59
By :
heng
No. 22
Guest
มันขึ้นมาแบบนี้คะ
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where (bmi between 20 and 24.9)' at line 1
แก้ 3 บรรทัดนี้ ก่อนเป็น
$sql = "select count(*) from bmi_db where sex='male' and bmi>25";
$sql = "select count(*) from bmi_db where sex='male' and bmi<20";
$sql = "select count(*) from bmi_db where sex='male' and (bmi between 20 and 24.9)";
SELECT
sex,
count(no)cnt_by_sex,
sum(case when BMI < 20 then 1 else 0 end) as thin,
sum(case when BMI between 20.1 and 24.9 then 1 else 0 end) as smart,
sum(case when BMI between 25 and 28.9 then 1 else 0 end) as fat,
sum(case when BMI >= 29 then 1 else 0 end) as very_fat
FROM temp
group by sex
order by sex
Date :
2010-07-19 19:58:02
By :
naskw
No. 26
Guest
sql ทั้งหมด
Code (PHP)
<?
$sql = "
SELECT
*
FROM(
SELECT
(select count(*) from bmi_db where sex = 'male') as count_male_all,
(select count(*) from bmi_db where sex = 'male' and BMI <20 ) as count_male_20,
(select count(*) from bmi_db where sex = 'male' and BMI >=20 and BMI <25 ) as count_male_25,
(select count(*) from bmi_db where sex = 'male' and BMI >=25 and BMI <29 ) as count_male_29,
(select count(*) from bmi_db where sex = 'male' and BMI >=29 ) as count_male_mex,
(select count(*) from bmi_db where sex = 'female') as count_female_all,
(select count(*) from bmi_db where sex = 'female' and BMI <20 ) as count_female_20,
(select count(*) from bmi_db where sex = 'female' and BMI >=20 and BMI <25 ) as count_female_25,
(select count(*) from bmi_db where sex = 'female' and BMI >=25 and BMI <29 ) as count_female_29,
(select count(*) from bmi_db where sex = 'female' and BMI >=29 ) as count_female_mex,
(select count(*) from bmi_db where age>=15 and age<=18) as count_15to18_all,
(select count(*) from bmi_db where age>=15 and age<=18 and BMI < 20) as count_15to18_20,
(select count(*) from bmi_db where age>=15 and age<=18 and BMI >=20 and BMI <25) as count_15to18_25,
(select count(*) from bmi_db where age>=15 and age<=18 and BMI >=25 and BMI <29) as count_15to18_29,
(select count(*) from bmi_db where age>=15 and age<=18 and BMI >=29) as count_15to18_mex,
(select count(*) from bmi_db where age>=19 and age<=25) as count_19to25_all,
(select count(*) from bmi_db where age>=19 and age<=25 and BMI < 20) as count_19to25_20,
(select count(*) from bmi_db where age>=19 and age<=25 and BMI >=20 and BMI <25) as count_19to25_25,
(select count(*) from bmi_db where age>=19 and age<=25 and BMI >=25 and BMI <29) as count_19to25_29,
(select count(*) from bmi_db where age>=19 and age<=25 and BMI >=29) as count_19to25_mex,
(select count(*) from bmi_db where age>=26 and age<=35) as count_26to35_all,
(select count(*) from bmi_db where age>=26 and age<=35 and BMI < 20) as count_26to35_20,
(select count(*) from bmi_db where age>=26 and age<=35 and BMI >=20 and BMI <25) as count_26to35_25,
(select count(*) from bmi_db where age>=26 and age<=35 and BMI >=25 and BMI <29) as count_26to35_29,
(select count(*) from bmi_db where age>=26 and age<=35 and BMI >=29) as count_26to35_mex,
(select count(*) from bmi_db where age>=36 and age<=45) as count_36to45_all,
(select count(*) from bmi_db where age>=36 and age<=45 and BMI < 20) as count_36to45_20,
(select count(*) from bmi_db where age>=36 and age<=45 and BMI >=20 and BMI <25) as count_36to45_25,
(select count(*) from bmi_db where age>=36 and age<=45 and BMI >=25 and BMI <29) as count_36to45_29,
(select count(*) from bmi_db where age>=36 and age<=45 and BMI >=29) as count_36to45_mex,
(select count(*) from bmi_db where age>=46 and age<=55) as count_46to55_all,
(select count(*) from bmi_db where age>=46 and age<=55 and BMI < 20) as count_46to55_20,
(select count(*) from bmi_db where age>=46 and age<=55 and BMI >=20 and BMI <25) as count_46to55_25,
(select count(*) from bmi_db where age>=46 and age<=55 and BMI >=25 and BMI <29) as count_46to55_29,
(select count(*) from bmi_db where age>=46 and age<=55 and BMI >=29) as count_46to55_mex
FROM
bmi_db LIMIT 0,1
)a
";
$query = mysql_query($sql);
$count_male_all = mysql_result($query,0,'count_male_all'); // ผู้ชายทั้งหมด
$count_male_20 = mysql_result($query,0,'count_male_20'); // ผู้ชายผอม
$count_male_25 = mysql_result($query,0,'count_male_25'); // ผู้ชายปกติ
$count_male_29 = mysql_result($query,0,'count_male_29'); // ผู้ชายอ้วน
$count_male_mex = mysql_result($query,0,'count_male_mex'); // ผู้ชายอ้วนมากๆ
$count_female_all = mysql_result($query,0,'count_female_all'); // ผู้หญิงทั้งหมด
$count_female_20 = mysql_result($query,0,'count_female_20'); // ผู้หญิงผอม
$count_female_25 = mysql_result($query,0,'count_female_25'); // ผู้หญิงปกติ
$count_female_29 = mysql_result($query,0,'count_female_29'); // ผู้หญิงอ้วน
$count_female_mex = mysql_result($query,0,'count_female_mex'); // ผู้หญิงอ้วนมากๆ
$count_15to18_all = mysql_result($query,0,'count_15to18_all'); // อายุ 15-18 ทั้งหมด
$count_15to18_20 = mysql_result($query,0,'count_15to18_20'); // อายุ 15-18 ผอม
$count_15to18_25 = mysql_result($query,0,'count_15to18_25'); // อายุ 15-18 ปกติ
$count_15to18_29 = mysql_result($query,0,'count_15to18_29'); // อายุ 15-18 อ้วน
$count_15to18_mex = mysql_result($query,0,'count_15to18_mex'); // อายุ 15-18 อ้วนมากๆ
// ที่เหลือลองเขียนเองดูก่อนนะ
?>
$sql = "SELECT*FROM(
SELECT
(select count(*) from bmi_db where sex = 'male') as count_male_all,
(select count(*) from bmi_db where sex = 'male' and BMI <20 ) as count_male_20,
(select count(*) from bmi_db where sex = 'male' and BMI >=20 and BMI <25 ) as count_male_25,
(select count(*) from bmi_db where sex = 'male' and BMI >=25 and BMI <29 ) as count_male_29,
(select count(*) from bmi_db where sex = 'male' and BMI >=29 ) as count_male_mex,
(select count(*) from bmi_db where sex = 'female') as count_female_all,
(select count(*) from bmi_db where sex = 'female' and BMI <20 ) as count_female_20,
(select count(*) from bmi_db where sex = 'female' and BMI >=20 and BMI <25 ) as count_female_25,
(select count(*) from bmi_db where sex = 'female' and BMI >=25 and BMI <29 ) as count_female_29,
(select count(*) from bmi_db where sex = 'female' and BMI >=29 ) as count_female_mex,
(select count(*) from bmi_db where age>=15 and age<=18) as count_15to18_all,
(select count(*) from bmi_db where age>=15 and age<=18 and BMI < 20) as count_15to18_20,
(select count(*) from bmi_db where age>=15 and age<=18 and BMI >=20 and BMI <25) as count_15to18_25,
(select count(*) from bmi_db where age>=15 and age<=18 and BMI >=25 and BMI <29) as count_15to18_29,
(select count(*) from bmi_db where age>=15 and age<=18 and BMI >=29) as count_15to18_mex,
(select count(*) from bmi_db where age>=19 and age<=25) as count_19to25_all,
(select count(*) from bmi_db where age>=19 and age<=25 and BMI < 20) as count_19to25_20,
(select count(*) from bmi_db where age>=19 and age<=25 and BMI >=20 and BMI <25) as count_19to25_25,
(select count(*) from bmi_db where age>=19 and age<=25 and BMI >=25 and BMI <29) as count_19to25_29,
(select count(*) from bmi_db where age>=19 and age<=25 and BMI >=29) as count_19to25_mex,
(select count(*) from bmi_db where age>=26 and age<=35) as count_26to35_all,
(select count(*) from bmi_db where age>=26 and age<=35 and BMI < 20) as count_26to35_20,
(select count(*) from bmi_db where age>=26 and age<=35 and BMI >=20 and BMI <25) as count_26to35_25,
(select count(*) from bmi_db where age>=26 and age<=35 and BMI >=25 and BMI <29) as count_26to35_29,
(select count(*) from bmi_db where age>=26 and age<=35 and BMI >=29) as count_26to35_mex,
(select count(*) from bmi_db where age>=36 and age<=45) as count_36to45_all,
(select count(*) from bmi_db where age>=36 and age<=45 and BMI < 20) as count_36to45_20,
(select count(*) from bmi_db where age>=36 and age<=45 and BMI >=20 and BMI <25) as count_36to45_25,
(select count(*) from bmi_db where age>=36 and age<=45 and BMI >=25 and BMI <29) as count_36to45_29,
(select count(*) from bmi_db where age>=36 and age<=45 and BMI >=29) as count_36to45_mex,
(select count(*) from bmi_db where age>=46 and age<=55) as count_46to55_all,
(select count(*) from bmi_db where age>=46 and age<=55 and BMI < 20) as count_46to55_20,
(select count(*) from bmi_db where age>=46 and age<=55 and BMI >=20 and BMI <25) as count_46to55_25,
(select count(*) from bmi_db where age>=46 and age<=55 and BMI >=25 and BMI <29) as count_46to55_29,
(select count(*) from bmi_db where age>=46 and age<=55 and BMI >=29) as count_46to55_mex
$sql = "SELECT*FROM(
SELECT
(select count(*) from bmi_db where sex = 'male') as count_male_all,
(select count(*) from bmi_db where sex = 'male' and BMI <20 ) as count_male_20,
(select count(*) from bmi_db where sex = 'male' and BMI >=20 and BMI <25 ) as count_male_25,
(select count(*) from bmi_db where sex = 'male' and BMI >=25 and BMI <29 ) as count_male_29,
(select count(*) from bmi_db where sex = 'male' and BMI >=29 ) as count_male_mex,
(select count(*) from bmi_db where sex = 'female') as count_female_all,
(select count(*) from bmi_db where sex = 'female' and BMI <20 ) as count_female_20,
(select count(*) from bmi_db where sex = 'female' and BMI >=20 and BMI <25 ) as count_female_25,
(select count(*) from bmi_db where sex = 'female' and BMI >=25 and BMI <29 ) as count_female_29,
(select count(*) from bmi_db where sex = 'female' and BMI >=29 ) as count_female_mex,
(select count(*) from bmi_db where age>=15 and age<=18) as count_15to18_all,
(select count(*) from bmi_db where age>=15 and age<=18 and BMI < 20) as count_15to18_20,
(select count(*) from bmi_db where age>=15 and age<=18 and BMI >=20 and BMI <25) as count_15to18_25,
(select count(*) from bmi_db where age>=15 and age<=18 and BMI >=25 and BMI <29) as count_15to18_29,
(select count(*) from bmi_db where age>=15 and age<=18 and BMI >=29) as count_15to18_mex,
(select count(*) from bmi_db where age>=19 and age<=25) as count_19to25_all,
(select count(*) from bmi_db where age>=19 and age<=25 and BMI < 20) as count_19to25_20,
(select count(*) from bmi_db where age>=19 and age<=25 and BMI >=20 and BMI <25) as count_19to25_25,
(select count(*) from bmi_db where age>=19 and age<=25 and BMI >=25 and BMI <29) as count_19to25_29,
(select count(*) from bmi_db where age>=19 and age<=25 and BMI >=29) as count_19to25_mex,
(select count(*) from bmi_db where age>=26 and age<=35) as count_26to35_all,
(select count(*) from bmi_db where age>=26 and age<=35 and BMI < 20) as count_26to35_20,
(select count(*) from bmi_db where age>=26 and age<=35 and BMI >=20 and BMI <25) as count_26to35_25,
(select count(*) from bmi_db where age>=26 and age<=35 and BMI >=25 and BMI <29) as count_26to35_29,
(select count(*) from bmi_db where age>=26 and age<=35 and BMI >=29) as count_26to35_mex,
(select count(*) from bmi_db where age>=36 and age<=45) as count_36to45_all,
(select count(*) from bmi_db where age>=36 and age<=45 and BMI < 20) as count_36to45_20,
(select count(*) from bmi_db where age>=36 and age<=45 and BMI >=20 and BMI <25) as count_36to45_25,
(select count(*) from bmi_db where age>=36 and age<=45 and BMI >=25 and BMI <29) as count_36to45_29,
(select count(*) from bmi_db where age>=36 and age<=45 and BMI >=29) as count_36to45_mex,
(select count(*) from bmi_db where age>=46 and age<=55) as count_46to55_all,
(select count(*) from bmi_db where age>=46 and age<=55 and BMI < 20) as count_46to55_20,
(select count(*) from bmi_db where age>=46 and age<=55 and BMI >=20 and BMI <25) as count_46to55_25,
(select count(*) from bmi_db where age>=46 and age<=55 and BMI >=25 and BMI <29) as count_46to55_29,
(select count(*) from bmi_db where age>=46 and age<=55 and BMI >=29) as count_46to55_mex
<?
$host="localhost";
$user="root";
$pass="123";
$dbname = "cal";
$connect=mysql_connect($host, $user, $pass) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$sql = "SELECT*FROM(
SELECT
(select count(*) from bmi_db where sex = 'male') as count_male_all,
(select count(*) from bmi_db where sex = 'male' and BMI <20 ) as count_male_20,
(select count(*) from bmi_db where sex = 'male' and BMI >=20 and BMI <25 ) as count_male_25,
(select count(*) from bmi_db where sex = 'male' and BMI >=25 and BMI <29 ) as count_male_29,
(select count(*) from bmi_db where sex = 'male' and BMI >=29 ) as count_male_mex,
(select count(*) from bmi_db where sex = 'female') as count_female_all,
(select count(*) from bmi_db where sex = 'female' and BMI <20 ) as count_female_20,
(select count(*) from bmi_db where sex = 'female' and BMI >=20 and BMI <25 ) as count_female_25,
(select count(*) from bmi_db where sex = 'female' and BMI >=25 and BMI <29 ) as count_female_29,
(select count(*) from bmi_db where sex = 'female' and BMI >=29 ) as count_female_mex,
(select count(*) from bmi_db where age>=15 and age<=18) as count_15to18_all,
(select count(*) from bmi_db where age>=15 and age<=18 and BMI < 20) as count_15to18_20,
(select count(*) from bmi_db where age>=15 and age<=18 and BMI >=20 and BMI <25) as count_15to18_25,
(select count(*) from bmi_db where age>=15 and age<=18 and BMI >=25 and BMI <29) as count_15to18_29,
(select count(*) from bmi_db where age>=15 and age<=18 and BMI >=29) as count_15to18_mex,
(select count(*) from bmi_db where age>=19 and age<=25) as count_19to25_all,
(select count(*) from bmi_db where age>=19 and age<=25 and BMI < 20) as count_19to25_20,
(select count(*) from bmi_db where age>=19 and age<=25 and BMI >=20 and BMI <25) as count_19to25_25,
(select count(*) from bmi_db where age>=19 and age<=25 and BMI >=25 and BMI <29) as count_19to25_29,
(select count(*) from bmi_db where age>=19 and age<=25 and BMI >=29) as count_19to25_mex,
(select count(*) from bmi_db where age>=26 and age<=35) as count_26to35_all,
(select count(*) from bmi_db where age>=26 and age<=35 and BMI < 20) as count_26to35_20,
(select count(*) from bmi_db where age>=26 and age<=35 and BMI >=20 and BMI <25) as count_26to35_25,
(select count(*) from bmi_db where age>=26 and age<=35 and BMI >=25 and BMI <29) as count_26to35_29,
(select count(*) from bmi_db where age>=26 and age<=35 and BMI >=29) as count_26to35_mex,
(select count(*) from bmi_db where age>=36 and age<=45) as count_36to45_all,
(select count(*) from bmi_db where age>=36 and age<=45 and BMI < 20) as count_36to45_20,
(select count(*) from bmi_db where age>=36 and age<=45 and BMI >=20 and BMI <25) as count_36to45_25,
(select count(*) from bmi_db where age>=36 and age<=45 and BMI >=25 and BMI <29) as count_36to45_29,
(select count(*) from bmi_db where age>=36 and age<=45 and BMI >=29) as count_36to45_mex,
(select count(*) from bmi_db where age>=46 and age<=55) as count_46to55_all,
(select count(*) from bmi_db where age>=46 and age<=55 and BMI < 20) as count_46to55_20,
(select count(*) from bmi_db where age>=46 and age<=55 and BMI >=20 and BMI <25) as count_46to55_25,
(select count(*) from bmi_db where age>=46 and age<=55 and BMI >=25 and BMI <29) as count_46to55_29,
(select count(*) from bmi_db where age>=46 and age<=55 and BMI >=29) as count_46to55_mex
FROM
bmi_db LIMIT 0,1
)a";
echo" <br>";
$query = mysql_query($sql);
if($select=="sex"){
echo"เลือก รายงานสถิติตามเพศ <br>";
$count_male_all = mysql_result($query,0,'count_male_all'); // ผู้ชายทั้งหมด
echo "เพศชาย มี ทั้งหมด ".$count_male_all." คน";
$count_male_20 = mysql_result($query,0,'count_male_20'); // ผู้ชายผอม
echo "อยู่ในเกณฑ์ผอม ".$count_male_20." คน"; // ผู้ชายทั้งหมด ...
$count_male_25 = mysql_result($query,0,'count_male_25'); // ผู้ชายปกติ
echo "อยู่ในเกณฑ์ปกติ ".$count_male_25." คน"; // ผู้ชายทั้งหมด ...
$count_male_29 = mysql_result($query,0,'count_male_29'); // ผู้ชายอ้วน
echo "อยู่ในเกณฑ์อ้วน ".$count_male_29." คน"; // ผู้ชายทั้งหมด ...
$count_male_mex = mysql_result($query,0,'count_male_mex'); // ผู้ชายอ้วนมากๆ
echo "อยู่ในเกณฑ์อ้วนมากๆ ".$count_male_mex." คน <br>"; // ผู้ชายทั้งหมด ...
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 105
มีอายุอยู่ระหว่าง 0 - 12 มีทั้งหมด คน
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 107
อยู่ในเกณฑ์ผอม คน
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 109
อยู่ในเกณฑ์ปกติ คน
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 111
อยู่ในเกณฑ์อ้วน คน
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 113
อยู่ในเกณฑ์อ้วนมากๆ คน
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 116
มีอายุอยู่ระหว่าง 13 - 19 มีทั้งหมด คน
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 118
อยู่ในเกณฑ์ผอม คน
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 120
อยู่ในเกณฑ์ปกติ คน
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 122
อยู่ในเกณฑ์อ้วน คน
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 124
อยู่ในเกณฑ์อ้วนมากๆ คน
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 127
มีอายุอยู่ระหว่าง 20 - 54 มีทั้งหมด คน
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 129
อยู่ในเกณฑ์ผอม คน
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 131
อยู่ในเกณฑ์ปกติ คน
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 133
อยู่ในเกณฑ์อ้วน คน
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 135
อยู่ในเกณฑ์อ้วนมากๆ คน
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 138
มีอายุอยู่ระหว่าง 55 - 100 มีทั้งหมด คน
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 140
อยู่ในเกณฑ์ผอม คน
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 142
อยู่ในเกณฑ์ปกติ คน
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 144
อยู่ในเกณฑ์อ้วน คน
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 146
อยู่ในเกณฑ์อ้วนมากๆ คน
รายงานตามเพศ
เลือก รายงานสถิติตามเพศ
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 78
เพศชาย มี ทั้งหมด คน
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 80
อยู่ในเกณฑ์ผอม คน
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 82
อยู่ในเกณฑ์ปกติ คน
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 84
อยู่ในเกณฑ์อ้วน คน
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 86
อยู่ในเกณฑ์อ้วนมากๆ คน
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 90
เพศหญิง มี ทั้งหมด คน
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 92
อยู่ในเกณฑ์ผอม คน
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 94
อยู่ในเกณฑ์ปกติ คน
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 96
อยู่ในเกณฑ์อ้วน คน
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hbo\tp.php on line 98
อยู่ในเกณฑ์อ้วนมากๆ คน
<?
$host="localhost";
$user="root";
$pass="123";
$dbname = "cal";
$connect=mysql_connect($host, $user, $pass) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$sql = "SELECT*FROM(
SELECT
(select count(*) from bmi_db where sex = 'male') as count_male_all,
(select count(*) from bmi_db where sex = 'male' and BMI <20 ) as count_male_20,
(select count(*) from bmi_db where sex = 'male' and BMI >=20 and BMI <25 ) as count_male_25,
(select count(*) from bmi_db where sex = 'male' and BMI >=25 and BMI <29 ) as count_male_29,
(select count(*) from bmi_db where sex = 'male' and BMI >=29 ) as count_male_mex,
(select count(*) from bmi_db where sex = 'female') as count_female_all,
(select count(*) from bmi_db where sex = 'female' and BMI <20 ) as count_female_20,
(select count(*) from bmi_db where sex = 'female' and BMI >=20 and BMI <25 ) as count_female_25,
(select count(*) from bmi_db where sex = 'female' and BMI >=25 and BMI <29 ) as count_female_29,
(select count(*) from bmi_db where sex = 'female' and BMI >=29 ) as count_female_mex,
(select count(*) from bmi_db where age>=1 and age<=12) as count_1to12_all,
(select count(*) from bmi_db where age>=1 and age<=12 and BMI < 20) as count_1to12_20,
(select count(*) from bmi_db where age>=1 and age<=12 and BMI >=20 and BMI <25) as count_1to12_25,
(select count(*) from bmi_db where age>=1 and age<=12 and BMI >=25 and BMI <29) as count_1to12_29,
(select count(*) from bmi_db where age>=1 and age<=12 and BMI >=29) as count_1to12_mex,
(select count(*) from bmi_db where age>=13 and age<=19) as count_13to19_all,
(select count(*) from bmi_db where age>=13 and age<=19 and BMI < 20) as count_13to19_20,
(select count(*) from bmi_db where age>=13 and age<=19 and BMI >=20 and BMI <25) as count_13to19_25,
(select count(*) from bmi_db where age>=13 and age<=19 and BMI >=25 and BMI <29) as count_13to19_29,
(select count(*) from bmi_db where age>=13 and age<=19 and BMI >=29) as count_13to19_mex,
(select count(*) from bmi_db where age>=20 and age<=54) as count_20to54_all,
(select count(*) from bmi_db where age>=20 and age<=54 and BMI < 20) as count_20to54_20,
(select count(*) from bmi_db where age>=20 and age<=54 and BMI >=20 and BMI <25) as count_20to54_25,
(select count(*) from bmi_db where age>=20 and age<=54 and BMI >=25 and BMI <29) as count_20to54_29,
(select count(*) from bmi_db where age>=20 and age<=54 and BMI >=29) as count_20to54_mex,
(select count(*) from bmi_db where age>=55 and age<=100) as count_55to100_all,
(select count(*) from bmi_db where age>=55 and age<=100 and BMI < 20) as count_55to100_20,
(select count(*) from bmi_db where age>=55 and age<=100 and BMI >=20 and BMI <25) as count_55to100_25,
(select count(*) from bmi_db where age>=55 and age<=100 and BMI >=25 and BMI <29) as count_55to100_29,
(select count(*) from bmi_db where age>=55 and age<=100 and BMI >=29) as count_55to100_mex,
<?
$host="localhost";
$user="root";
$pass="12345";
$dbname = "cal";
$connect=mysql_connect($host, $user, $pass) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$sql = "SELECT*FROM(
SELECT
(select count(*) from bmi_db where sex = 'male') as count_male_all,
(select count(*) from bmi_db where sex = 'male' and BMI <20 ) as count_male_20,
(select count(*) from bmi_db where sex = 'male' and BMI >=20 and BMI <25 ) as count_male_25,
(select count(*) from bmi_db where sex = 'male' and BMI >=25 and BMI <29 ) as count_male_29,
(select count(*) from bmi_db where sex = 'male' and BMI >=29 ) as count_male_mex,
(select count(*) from bmi_db where sex = 'female') as count_female_all,
(select count(*) from bmi_db where sex = 'female' and BMI <20 ) as count_female_20,
(select count(*) from bmi_db where sex = 'female' and BMI >=20 and BMI <25 ) as count_female_25,
(select count(*) from bmi_db where sex = 'female' and BMI >=25 and BMI <29 ) as count_female_29,
(select count(*) from bmi_db where sex = 'female' and BMI >=29 ) as count_female_mex,
(select count(*) from bmi_db where age>=1 and age<=12) as count_1to12_all,
(select count(*) from bmi_db where age>=1 and age<=12 and BMI < 20) as count_1to12_20,
(select count(*) from bmi_db where age>=1 and age<=12 and BMI >=20 and BMI <25) as count_1to12_25,
(select count(*) from bmi_db where age>=1 and age<=12 and BMI >=25 and BMI <29) as count_1to12_29,
(select count(*) from bmi_db where age>=1 and age<=12 and BMI >=29) as count_1to12_mex,
(select count(*) from bmi_db where age>=13 and age<=19) as count_13to19_all,
(select count(*) from bmi_db where age>=13 and age<=19 and BMI < 20) as count_13to19_20,
(select count(*) from bmi_db where age>=13 and age<=19 and BMI >=20 and BMI <25) as count_13to19_25,
(select count(*) from bmi_db where age>=13 and age<=19 and BMI >=25 and BMI <29) as count_13to19_29,
(select count(*) from bmi_db where age>=13 and age<=19 and BMI >=29) as count_13to19_mex,
(select count(*) from bmi_db where age>=20 and age<=54) as count_20to54_all,
(select count(*) from bmi_db where age>=20 and age<=54 and BMI < 20) as count_20to54_20,
(select count(*) from bmi_db where age>=20 and age<=54 and BMI >=20 and BMI <25) as count_20to54_25,
(select count(*) from bmi_db where age>=20 and age<=54 and BMI >=25 and BMI <29) as count_20to54_29,
(select count(*) from bmi_db where age>=20 and age<=54 and BMI >=29) as count_20to54_mex,
(select count(*) from bmi_db where age>=55 and age<=100) as count_55to100_all,
(select count(*) from bmi_db where age>=55 and age<=100 and BMI < 20) as count_55to100_20,
(select count(*) from bmi_db where age>=55 and age<=100 and BMI >=20 and BMI <25) as count_55to100_25,
(select count(*) from bmi_db where age>=55 and age<=100 and BMI >=25 and BMI <29) as count_55to100_29,
(select count(*) from bmi_db where age>=55 and age<=100 and BMI >=29) as count_55to100_mex