 |
|
|
 |
 |
|
ต้องใช้ count อ่ะครับ
เช่นจะนับว่ามีเพศชายกี่คนก็ select count(*) from bmi_db where sex='male'
ถ้าจะหาจำนวนเพศชายที่อ้วนก็ select count(*) from bmi_db where sex='male' where bmi>เกณฑ์
ประมาณนี้
|
 |
 |
 |
 |
Date :
2010-07-10 21:36:49 |
By :
blacklion |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มีโค๊ดเต็มๆไหมคะ หรือโค๊ดตัวอย่างก็ได้คะ มือใหม่คะ ขอโทษที่รบกวนคะ
|
 |
 |
 |
 |
Date :
2010-07-10 21:44:49 |
By :
ยี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
นี้เป็นเกณฑ์วัดว่าอยู่ในเกณฑ์ไหนคะ
น้อยกว่า 20.0 ผอม
20.0-24.9 ปรกติ
มากกว่าหรือเท่ากับ 25 อ้วน
มากกว่าหรือเท่ากับ 29 อ้วนมากๆ
ช่วยหน่อยนะคะพี่sahachai หรือพี่ๆคนไหนก็ได้คะ ขอโค๊ดตัวอย่างก็ได้คะ
|
 |
 |
 |
 |
Date :
2010-07-10 23:12:51 |
By :
ยี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
add mail มาดีก่า เด่ว ช่วย [email protected]
|
 |
 |
 |
 |
Date :
2010-07-10 23:47:57 |
By :
deathzap |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จำนวนผู้ชาย = 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)
ปล. ไอ้โค๊ดเต็มๆ นี่คืออะไรน้อครับ
|
 |
 |
 |
 |
Date :
2010-07-10 23:57:52 |
By :
blacklion |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้addmailแล้วนะคะ พี่Wanted ขอบคุณคะ
|
 |
 |
 |
 |
Date :
2010-07-11 10:22:47 |
By :
ยี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่มีใครช่วยอีก หรือคะ
|
 |
 |
 |
 |
Date :
2010-07-15 21:17:32 |
By :
ช่วยหน่อย |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่มีใครช่วยเลย เศร้าจัง 
|
 |
 |
 |
 |
Date :
2010-07-16 17:01:29 |
By :
ช่วยหน่อย |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดูโค้ดนี้ครับ แต่ต้องเปลี่ยนชื่อฟิลด์หน่อยนะครับ
https://www.thaicreate.com/php/forum/041598.html
<?
$host="localhost";
$user="root";
$pass="12345";
$dbname1 = "age";
$connect=mysql_connect($host, $user, $pass) or die(mysql_error());
mysql_select_db($dbname1) or die(mysql_error());
$sql="select count(*) as age_count, group_concat(nm) as names, current_date, bd,
year(current_date)-year(bd) + if( date_format( current_date, '%m%d' ) > date_format( bd, '%m%d' ) , 1, 0 ) as age
from user_profiles
group by
year(current_date)-year(bd) + if(date_format(current_date,'%m%d') > date_format(bd,'%m%d'),1,0) ";
$res = mysql_query($sql )or die(mysql_error());
$numr = mysql_num_rows($res);
while($row = mysql_fetch_assoc($res)){
echo $row['age_count'],'........',$row['names'],'.......',$row['curent_date'],'.......',$row['bd'],'.......',$row['age'],'<br>';
}
echo '<hr>';
$sql1="SELECT
group_concat( NAMES ) AS age_range_names,
sum( age_count ) AS age_range_count,
if( age >=60, 'more than 60', if( age >=50, '50-59', if( age >=40, '40-49', 'less than 40' ) ) ) AS age_range
FROM
(SELECT
count( * ) AS age_count,
group_concat( nm ) AS NAMES ,
current_date,
bd,
year( current_date ) - year( bd ) + if( date_format( current_date, '%m%d' ) > date_format( bd, '%m%d' ) , 0, -1 ) AS age
FROM user_profiles
GROUP BY
year( current_date ) - year( bd ) + if( date_format( current_date, '%m%d' ) > date_format( bd, '%m%d' ) , 0, -1 )
) AS user_ages
GROUP BY if( age >=60, 'C6', if( age >=50, 'C5', if( age >=40, 'C4', 'C3' ) ) )
";
$res = mysql_query($sql1 )or die(mysql_error());
$numr = mysql_num_rows($res);
while($row = mysql_fetch_assoc($res)){
echo $row['age_range_names'],'........',$row['age_range_count'],'.......',$row['age_range'],'<br>';
}
?>
|
 |
 |
 |
 |
Date :
2010-07-17 08:31:46 |
By :
num |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่วยอธิบายโค๊ดหน่อยได้ไหมคะ นี้รู้สึกว่ามันเกียวกับคำนวณ อายุ สักอย่างนะคะ ที่หนูอยากได้โค๊ดที่หนูได้ตั้งกระทุ้ไว้นะคะ [font=Verdana][/font]ช่วยหูได้ไหมคะ มัเกี่ยวกับโปรเจคจบอะคะ ขอร้องจริงๆคะ
https://www.thaicreate.com/tutorial/sql-group_concat.html
|
 |
 |
 |
 |
Date :
2010-07-17 21:20:55 |
By :
ช่วยหน่อย |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่วยหน่อยคะ เกี่ยวกับโปรเจคอะคะ เหลืออันนี้อันเดียวแล้วคะ ขอคำแนะนำด้วยคะ
|
 |
 |
 |
 |
Date :
2010-07-18 18:15:58 |
By :
ช่วยหน่อย |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เศร้าจัง ไม่มีใครช่วยหรือคะ
|
 |
 |
 |
 |
Date :
2010-07-19 09:32:28 |
By :
ยี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณอยากให้ช่วยอะไรอ่ะครับ ....
บอกไปเลยก็ได้ว่าช่วย ทำ ให้หน่อยจะดีกว่า
ที่ข้างบนเขาหยิบยกมาให้คุณ เขาช่วยคุณแล้วครับ เขาไม่บอกคำตอบทั้งหมดเพื่อให้คุณนั่นแหละไปทำเอง
เพราะเขาแนะนำว่าแนวทางว่าควรจะเดินทางไหนเท่านั้น
แต่ถ้าคุณบอกว่า คุณไม่รู้คุณก็บอกไปเลยครับว่า ทำ ให้หน่อย
รับรองได้อย่างคุณต้องการแน่นอนครับ
|
 |
 |
 |
 |
Date :
2010-07-19 10:38:04 |
By :
oxygenyoyo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่วยทำให้หน่อยคะ ได้ไหมคะ
|
 |
 |
 |
 |
Date :
2010-07-19 10:55:52 |
By :
ยี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สำหรับผมคง ไม่ได้ ครับผมสนับสนุนคนทำเองครับ
รอท่านอื่นที่ใจดีกว่าผมมาช่วยแล้วกันครับ แต่ถ้ารอไม่ไหวก็ลองดิ้นรนดูครับ
|
 |
 |
 |
 |
Date :
2010-07-19 11:22:24 |
By :
oxygenyoyo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผิดตรงไหนหรอ คะ ช่วยแนะนำหน่อย
Parse error: syntax error, unexpected T_STRING in C:\AppServ\www\hbo\adin.php on line 38
โค๊ดคะ
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {
color: #FF0000;
font-weight: bold;
}
body {
background-image: url(image/background.gif);
}
-->
</style>
</head>
<body>
<div align="center">
<p> </p>
<p class="style1">ยินดีต้อนรับค่ะ</p>
<form id="form1" name="form1" method="post" action="">
<label>
<select name="select">
<option value="0" selected="selected">โปรดเลือก</option>
<option value="1">รายงานสถิติตามเพศ</option>
<option value="2">รายงานสถิติตามอายุ</option>
</select>
</label><?
$host="localhost";
$user="root";
$pass="123";
$dbname = "bmr";
$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)
$res = mysql_query($sql )or die(mysql_error());
$numr = mysql_num_rows($res);
while($row = mysql_fetch_assoc($res)){
echo $row['age_count'],'........',$row['names'],'.......',$row['curent_date'],'.......',$row['bd'],'.......',$row['age'],'<br>';
}
?>
<p>
</p>
</form>
<p class="style1"> </p>
<p class="style1"> </p>
</div>
</body>
</html>
|
 |
 |
 |
 |
Date :
2010-07-19 11:52:56 |
By :
ย |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Parse error: syntax error, unexpected T_STRING in C:\AppServ\www\hbo\adin.php on line 38
บรรทัดที่ 38 อ่ะครับคุณเขียนยังไงแล้วก่อนนั้นลืมเติม ; หรือเปล่า
|
 |
 |
 |
 |
Date :
2010-07-19 12:25:02 |
By :
oxygenyoyo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใส่ ;แล้วยังerrorเหมือนเดิม
|
 |
 |
 |
 |
Date :
2010-07-19 12:37:35 |
By :
ยี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตรง sql ใส่ " ด้วยนะ
$sql = " select count(*) from bmi_db where sex='male' ";
|
 |
 |
 |
 |
Date :
2010-07-19 15:55:43 |
By :
heng |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันขึ้นว่า
No database selected คะ
แล้วจะให้มันแสดงตามที่เราเลือกได้ยังไงคะ รบกวนหน่อยคะพี่
|
 |
 |
 |
 |
Date :
2010-07-19 16:56:13 |
By :
ยี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
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 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันขึ้นมาแบบนี้คะ
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
แล้วเราจะเลือกว่า รายงานตามอายุ และตามเพศยังไงคะ จะแสดงตามที่ขึ้นกระทู้ไว้ยังไงคะ
|
 |
 |
 |
 |
Date :
2010-07-19 17:39:53 |
By :
ยี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้ 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)";
|
 |
 |
 |
 |
Date :
2010-07-19 17:57:45 |
By :
heng |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันขึ้นมา แบบนี้
.............................
อย่างนี้คะ ต้องทำอย่างไรคะ
|
 |
 |
 |
 |
Date :
2010-07-19 18:09:36 |
By :
ยี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเอา SQL นี่ไปรันดูนะ อันนี้ดูแบบตามเพศ รันทีเดียวได้ครบทุกอย่าง
Code (PHP)
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 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
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 อ้วนมากๆ
// ที่เหลือลองเขียนเองดูก่อนนะ
?>
|
 |
 |
 |
 |
Date :
2010-07-19 21:15:53 |
By :
heng |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทำไมพอเลือก รายงานตามสถิติ รายงานตามเพศ มันถึงไม่แสดงออกมาเลยหรือคะ ไม่แสดงออกมาเลย ว่า เพศชาย มีทั้งหมด = xxx ประมาณนี้หรือคะ ผิดตรงไหนคะ ช่วยแนะนำหน่อยคะ
นี้โค๊ดคะ
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label>
<select name="select">
<option value="0" selected="selected">โปรดเลือก</option>
<option value="sex">รายงานสถิติตามเพศ</option>
<option value="age">รายงานสถิติตามอายุ</option>
</select>
<label>
<?
$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";
$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 อ้วนมากๆ
// ที่เหลือลองเขียนเองดูก่อนนะ
?>
</body>
</html>
|
 |
 |
 |
 |
Date :
2010-07-19 23:06:01 |
By :
ยี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยังไม่ได้ echo ตัวแปรเลยอ่ะ
echo $count_male_all; // ผู้ชายทั้งหมด ...
echo ตัวแปรให้หมดถ้าต้องการให้แสดงอันไหนก็ echo ตัวแปรนั้น
แล้วอันนี้ยังไม่ได้ทำแยกนะ ที่เลือกตามเพศ ตามอายุ ลองอันนี้ให้ผ่านก่อน
|
 |
 |
 |
 |
Date :
2010-07-19 23:23:05 |
By :
heng |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผ่านแล้วคะ แต่มันไม่เห็ขึ้นว่า ผู้ชายทั้งหมด xxx คน มันขึ้น x ไม่ขึ้นตัวหนังสือ และอีกอย่างทำไมยังไม่สามารถเลือกได้คะ ขอบคุณที่แนะนำคะ
|
 |
 |
 |
 |
Date :
2010-07-20 00:10:03 |
By :
ยี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณ ยี ครับ คุณมีหนังสือ PHP หรือเปล่าถ้ามีลองศึกษาตามหนังสือดูก่อนนะครับ ถ้าไม่มี คลิกตรงนี้ แล้วลองศึกษาดู เพราะเท่าที่ผมอ่านดูรู้สึกว่าคุณจะยังไม่ได้ศึกษาพื้นฐานมาเลย
|
 |
 |
 |
 |
Date :
2010-07-20 09:01:52 |
By :
naskw |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณ heng คะ ช่วยด้วยคะ
|
 |
 |
 |
 |
Date :
2010-07-20 09:26:06 |
By :
ยี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เหมือนทำกันให้ทุกอย่างเลยเนอะ อะ...! ไหนก็ไหนๆ แหละ ลองเอา code ที่มีอยู่ตอนนี้มาดูสิ
จะได้รู้ว่าถึงตรงไหน ได้ตามช่วยแก้กันถูก
|
 |
 |
 |
 |
Date :
2010-07-20 09:34:02 |
By :
aimoomoo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
นี้โค๊ดคะ
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label>
<select name="select">
<option value="0" selected="selected">โปรดเลือก</option>
<option value="sex">รายงานสถิติตามเพศ</option>
<option value="age">รายงานสถิติตามอายุ</option>
</select>
<label>
<?
$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";
$query = mysql_query($sql);
$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; // ผู้ชายทั้งหมด ...
$count_female_all = mysql_result($query,0,'count_female_all'); // ผู้หญิงทั้งหมด
echo $count_female_all; // ผู้ชายทั้งหมด ...
$count_female_20 = mysql_result($query,0,'count_female_20'); // ผู้หญิงผอม
echo $count_female_20; // ผู้ชายทั้งหมด ...
$count_female_25 = mysql_result($query,0,'count_female_25'); // ผู้หญิงปกติ
echo $count_female_25; // ผู้ชายทั้งหมด ...
$count_female_29 = mysql_result($query,0,'count_female_29'); // ผู้หญิงอ้วน
echo $count_female_29; // ผู้ชายทั้งหมด ...
$count_female_mex = mysql_result($query,0,'count_female_mex'); // ผู้หญิงอ้วนมากๆ
echo $count_female_mex; // ผู้ชายทั้งหมด ...
$count_15to18_all = mysql_result($query,0,'count_15to18_all'); // อายุ 15-18 ทั้งหมด
echo $count_15to18_all; //
$count_15to18_20 = mysql_result($query,0,'count_15to18_20'); // อายุ 15-18 ผอม
echo $count_15to18_20;
$count_15to18_25 = mysql_result($query,0,'count_15to18_25'); // อายุ 15-18 ปกติ
echo $count_15to18_25;
$count_15to18_29 = mysql_result($query,0,'count_15to18_29'); // อายุ 15-18 อ้วน
echo $count_15to18_29;
$count_15to18_mex = mysql_result($query,0,'count_15to18_mex'); // อายุ 15-18 อ้วนมากๆ
echo $count_15to18_mex;
// ที่เหลือลองเขียนเองดูก่อนนะ
?>
</body>
</html>
|
 |
 |
 |
 |
Date :
2010-07-20 09:38:43 |
By :
ยี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เดียวจัดให้แปบ
|
 |
 |
 |
 |
Date :
2010-07-20 10:21:55 |
By :
aimoomoo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จ้า
|
 |
 |
 |
 |
Date :
2010-07-20 10:25:50 |
By :
ยี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณยีครับ คุณลองดีไซด์ดูก่อนนะ เช่น
<table align="center" border="0" cellpadding="1" cellspacing="1">
<tr>
<td>
ผู้ชายทั้งหมด <?=$count_male_all?> คน
ผู้ชายผอม <?=$count_male_20?> คน
ผู้ชายปกติ <?=$count_male_25?> คน
ผู้ชายอ้วน <?=$count_male_29?> คน
ผู้ชายอ้วนมาก ๆ <?=$count_male_mex?> คน
</td>
</tr>
<tr>
<td>
ผู้หญิงทั้งหมด <?=$count_female_all?> คน
ผู้หญิงผอม <?=$count_female_20?> คน
ผู้ชหญิงปกติ <?=$count_female_25?> คน
ผู้หญิงอ้วน <?=$count_female_29?> คน
ผู้หญิงอ้วนมาก ๆ <?=$count_female_mex?> คน
</td>
</tr>
</table>
ประมาณนี้
|
 |
 |
 |
 |
Date :
2010-07-20 10:48:20 |
By :
heng |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แล้วให้มันสามารถเลือดแสดงแบบ รายงานตามอายุ ตามเพศ ยังไงคะ
|
 |
 |
 |
 |
Date :
2010-07-20 10:50:31 |
By :
ยี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาอันนี้ไปลองดู ปรับปรุงตาม code ที่ให้มา
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>Untitled Document</title>
</head>
<body>
<center>
<form name="form1" method="post" action="">
<select name="select">
<option value="0" selected="selected">โปรดเลือก</option>
<option value="sex">รายงานสถิติตามเพศ</option>
<option value="age">รายงานสถิติตามอายุ</option>
</select>
<input type="submit" name="button" id="button" value="Submit" />
</form>
<br /><br />
<?
$select=$_POST[select];
?>
</center>
<?
$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>"; // ผู้ชายทั้งหมด ...
$count_female_all = mysql_result($query,0,'count_female_all'); // ผู้หญิงทั้งหมด
echo "เพศหญิง มี ทั้งหมด ".$count_female_all." คน"; // ผู้ชายทั้งหมด ...
$count_female_20 = mysql_result($query,0,'count_female_20'); // ผู้หญิงผอม
echo "อยู่ในเกณฑ์ผอม ".$count_female_20." คน"; // ผู้ชายทั้งหมด ...
$count_female_25 = mysql_result($query,0,'count_female_25'); // ผู้หญิงปกติ
echo "อยู่ในเกณฑ์ปกติ ".$count_female_25." คน"; // ผู้ชายทั้งหมด ...
$count_female_29 = mysql_result($query,0,'count_female_29'); // ผู้หญิงอ้วน
echo "อยู่ในเกณฑ์อ้วน ".$count_female_29." คน"; // ผู้ชายทั้งหมด ...
$count_female_mex = mysql_result($query,0,'count_female_mex'); // ผู้หญิงอ้วนมากๆ
echo "อยู่ในเกณฑ์อ้วนมากๆ ".$count_female_mex." คน"; // ผู้ชายทั้งหมด ...
}
##################################################################
if($select=="age"){
echo"เลือก รายงานสถิติตามอายุ <br>";
//15-18
$count_15to18_all = mysql_result($query,0,'count_15to18_all'); // อายุ 15-18 ทั้งหมด
echo "มีอายุอยู่ระหว่าง 15-18 มีทั้งหมด ".$count_15to18_all." คน"; //
$count_15to18_20 = mysql_result($query,0,'count_15to18_20'); // อายุ 15-18 ผอม
echo "อยู่ในเกณฑ์ผอม ".$count_15to18_20. " คน";
$count_15to18_25 = mysql_result($query,0,'count_15to18_25'); // อายุ 15-18 ปกติ
echo "อยู่ในเกณฑ์ปกติ ".$count_15to18_25. " คน";
$count_15to18_29 = mysql_result($query,0,'count_15to18_29'); // อายุ 15-18 อ้วน
echo "อยู่ในเกณฑ์อ้วน ".$count_15to18_29. " คน";
$count_15to18_mex = mysql_result($query,0,'count_15to18_mex'); // อายุ 15-18 อ้วนมากๆ
echo "อยู่ในเกณฑ์อ้วนมากๆ ".$count_15to18_mex. " คน <br>";
//19-25
$count_19to25_all = mysql_result($query,0,'count_19to25_all'); // อายุ 15-18 ทั้งหมด
echo "มีอายุอยู่ระหว่าง 19-25 มีทั้งหมด ".$count_19to25_all." คน"; //
$count_19to25_20 = mysql_result($query,0,'count_19to25_20'); // อายุ 15-18 ผอม
echo "อยู่ในเกณฑ์ผอม ".$count_19to25_20. " คน";
$count_19to25_25 = mysql_result($query,0,'count_19to25_25'); // อายุ 15-18 ปกติ
echo "อยู่ในเกณฑ์ปกติ ".$count_19to25_25. " คน";
$count_19to25_29 = mysql_result($query,0,'count_19to25_29'); // อายุ 15-18 อ้วน
echo "อยู่ในเกณฑ์อ้วน ".$count_19to25_29. " คน";
$count_19to25_mex = mysql_result($query,0,'count_19to25_mex'); // อายุ 15-18 อ้วนมากๆ
echo "อยู่ในเกณฑ์อ้วนมากๆ ".$count_19to25_mex. " คน<br>";
//26-35
$count_26to35_all = mysql_result($query,0,'count_26to35_all'); // อายุ 15-18 ทั้งหมด
echo "มีอายุอยู่ระหว่าง 26-35 มีทั้งหมด ".$count_26to35_all." คน"; //
$count_26to35_20 = mysql_result($query,0,'count_26to35_20'); // อายุ 15-18 ผอม
echo "อยู่ในเกณฑ์ผอม ".$count_26to35_20. " คน";
$count_26to35_25 = mysql_result($query,0,'count_26to35_25'); // อายุ 15-18 ปกติ
echo "อยู่ในเกณฑ์ปกติ ".$count_26to35_25. " คน";
$count_26to35_29 = mysql_result($query,0,'count_26to35_29'); // อายุ 15-18 อ้วน
echo "อยู่ในเกณฑ์อ้วน ".$count_26to35_29. " คน";
$count_26to35_mex = mysql_result($query,0,'count_26to35_mex'); // อายุ 15-18 อ้วนมากๆ
echo "อยู่ในเกณฑ์อ้วนมากๆ ".$count_26to35_mex. " คน<br>";
//36-45
$count_36to45_all = mysql_result($query,0,'count_36to45_all'); // อายุ 15-18 ทั้งหมด
echo "มีอายุอยู่ระหว่าง 36-45 มีทั้งหมด ".$count_36to45_all." คน"; //
$count_36to45_20 = mysql_result($query,0,'count_36to45_20'); // อายุ 15-18 ผอม
echo "อยู่ในเกณฑ์ผอม ".$count_36to45_20. " คน";
$count_36to45_25 = mysql_result($query,0,'count_36to45_25'); // อายุ 15-18 ปกติ
echo "อยู่ในเกณฑ์ปกติ ".$count_36to45_25. " คน";
$count_36to45_29 = mysql_result($query,0,'count_36to45_29'); // อายุ 15-18 อ้วน
echo "อยู่ในเกณฑ์อ้วน ".$count_36to45_29. " คน";
$count_36to45_mex = mysql_result($query,0,'count_36to45_mex'); // อายุ 15-18 อ้วนมากๆ
echo "อยู่ในเกณฑ์อ้วนมากๆ ".$count_36to45_mex. " คน<br>";
//46-55
$count_46to55_all = mysql_result($query,0,'count_46to55_all'); // อายุ 15-18 ทั้งหมด
echo "มีอายุอยู่ระหว่าง 46-55 มีทั้งหมด ".$count_46to55_all." คน"; //
$count_46to55_20 = mysql_result($query,0,'count_46to55_20'); // อายุ 15-18 ผอม
echo "อยู่ในเกณฑ์ผอม ".$count_46to55_20. " คน";
$count_46to55_25 = mysql_result($query,0,'count_46to55_25'); // อายุ 15-18 ปกติ
echo "อยู่ในเกณฑ์ปกติ ".$count_46to55_25. " คน";
$count_46to55_29 = mysql_result($query,0,'count_46to55_29'); // อายุ 15-18 อ้วน
echo "อยู่ในเกณฑ์อ้วน ".$count_46to55_29. " คน";
$count_46to55_mex = mysql_result($query,0,'count_46to55_mex'); // อายุ 15-18 อ้วนมากๆ
echo "อยู่ในเกณฑ์อ้วนมากๆ ".$count_46to55_mex. " คน";
}
// ที่เหลือลองเขียนเองดูก่อนนะ
?>
</body>
</html>
|
 |
 |
 |
 |
Date :
2010-07-20 10:59:04 |
By :
aimoomoo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณคะ
|
 |
 |
 |
 |
Date :
2010-07-20 11:02:59 |
By :
ยี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เกือบลืม แก้ตรงนี้ให้ตรงกับของตนเองด้วยนะ
$pass="123";
|
 |
 |
 |
 |
Date :
2010-07-20 11:08:49 |
By :
aimoomoo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากจ้า
|
 |
 |
 |
 |
Date :
2010-07-20 14:13:45 |
By :
ยี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พี่ๆคะ ทำไมพอหนูเปลี่ยนโค๊ด นิดหน่อยมัน error อย่างนี้คะ
รายงานตามอายุ
เลือก รายงานสถิติตามอายุ
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
อยู่ในเกณฑ์อ้วนมากๆ คน
มันผิดตรงไหนหรือคะ แก้หลายครั้งแล้ว งงมาก
|
 |
 |
 |
 |
Date :
2010-07-20 21:22:03 |
By :
ยี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาโค๊ดที่เปลี่ยนมาดูด้วยสิจ๊ะ
|
 |
 |
 |
 |
Date :
2010-07-20 22:24:36 |
By :
heng |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
นี้คะ โค๊ด
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>Untitled Document</title>
</head>
<body>
<center>
<form name="form1" method="post" action="">
<select name="select">
<option value="0" selected="selected">โปรดเลือก</option>
<option value="sex">รายงานสถิติตามเพศ</option>
<option value="age">รายงานสถิติตามอายุ</option>
</select>
<input type="submit" name="button" id="button" value="Submit" />
</form>
<br /><br />
<?
$select=$_POST[select];
?>
</center>
<?
$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,
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>"; // ผู้ชายทั้งหมด ...
$count_female_all = mysql_result($query,0,'count_female_all'); // ผู้หญิงทั้งหมด
echo "เพศหญิง มี ทั้งหมด ".$count_female_all." คน"; // ผู้หญิงทั้งหมด ...
$count_female_20 = mysql_result($query,0,'count_female_20'); // ผู้หญิงผอม
echo "อยู่ในเกณฑ์ผอม ".$count_female_20." คน"; // ผู้ชายทั้งหมด ...
$count_female_25 = mysql_result($query,0,'count_female_25'); // ผู้หญิงปกติ
echo "อยู่ในเกณฑ์ปกติ ".$count_female_25." คน"; // ผู้ชายทั้งหมด ...
$count_female_29 = mysql_result($query,0,'count_female_29'); // ผู้หญิงอ้วน
echo "อยู่ในเกณฑ์อ้วน ".$count_female_29." คน"; // ผู้ชายทั้งหมด ...
$count_female_mex = mysql_result($query,0,'count_female_mex'); // ผู้หญิงอ้วนมากๆ
echo "อยู่ในเกณฑ์อ้วนมากๆ ".$count_female_mex." คน"; // ผู้ชายทั้งหมด ...
}
##################################################################
if($select=="age"){
echo"เลือก รายงานสถิติตามอายุ <br>";
//1-12
$count_1to12_all = mysql_result($query,0,'count_1to12_all'); // อายุ 0-12 ทั้งหมด
echo "มีอายุอยู่ระหว่าง 0 - 12 มีทั้งหมด ".$count_1to12_all." คน"; //
$count_1to12_20 = mysql_result($query,0,'count_1to12_20'); // อายุ 0-12 ผอม
echo "อยู่ในเกณฑ์ผอม ".$count_1to12_20. " คน";
$count_1to12_25 = mysql_result($query,0,'count_1to12_25'); // อายุ 0-12 ปกติ
echo "อยู่ในเกณฑ์ปกติ ".$count_1to12_25. " คน";
$count_1to12_29 = mysql_result($query,0,'count_1to12_29'); // อายุ 0-12 อ้วน
echo "อยู่ในเกณฑ์อ้วน ".$count_1to12_29. " คน";
$count_1to12_mex = mysql_result($query,0,'count_1to12_mex'); // อายุ 0-12 อ้วนมากๆ
echo "อยู่ในเกณฑ์อ้วนมากๆ ".$count_1to12_mex. " คน <br>";
//13 - 19
$count_13to19_all = mysql_result($query,0,'count_13to19_all'); // อายุ 15-18 ทั้งหมด
echo "มีอายุอยู่ระหว่าง 13 - 19 มีทั้งหมด ".$count_13to19_all." คน"; //
$count_13to19_20 = mysql_result($query,0,'count_13to19_20'); // อายุ 15-18 ผอม
echo "อยู่ในเกณฑ์ผอม ".$count_13to19_20. " คน";
$count_13to19_25 = mysql_result($query,0,'count_13to19_25'); // อายุ 15-18 ปกติ
echo "อยู่ในเกณฑ์ปกติ ".$count_13to19_25. " คน";
$count_13to19_29 = mysql_result($query,0,'count_13to19_29'); // อายุ 15-18 อ้วน
echo "อยู่ในเกณฑ์อ้วน ".$count_13to19_29. " คน";
$count_13to19_mex = mysql_result($query,0,'count_13to19_mex'); // อายุ 15-18 อ้วนมากๆ
echo "อยู่ในเกณฑ์อ้วนมากๆ ".$count_13to19_mex. " คน<br>";
//20 - 54
$count_20to54_all = mysql_result($query,0,'count_20to54_all'); // อายุ 15-18 ทั้งหมด
echo "มีอายุอยู่ระหว่าง 20 - 54 มีทั้งหมด ".$count_20to54_all." คน"; //
$count_20to54_20 = mysql_result($query,0,'count_20to54_20'); // อายุ 15-18 ผอม
echo "อยู่ในเกณฑ์ผอม ".$count_20to54_20. " คน";
$count_20to54_25 = mysql_result($query,0,'count_20to54_25'); // อายุ 15-18 ปกติ
echo "อยู่ในเกณฑ์ปกติ ".$count_20to54_25. " คน";
$count_20to54_29 = mysql_result($query,0,'count_20to54_29'); // อายุ 15-18 อ้วน
echo "อยู่ในเกณฑ์อ้วน ".$count_20to54_29. " คน";
$count_20to54_mex = mysql_result($query,0,'count_20to54_mex'); // อายุ 15-18 อ้วนมากๆ
echo "อยู่ในเกณฑ์อ้วนมากๆ ".$count_20to54_mex. " คน<br>";
//55 - 100
$count_55to100_all = mysql_result($query,0,'count_55to100_all'); // อายุ 15-18 ทั้งหมด
echo "มีอายุอยู่ระหว่าง 55 - 100 มีทั้งหมด ".$count_55to100_all." คน"; //
$count_55to100_20 = mysql_result($query,0,'count_55to100_20'); // อายุ 15-18 ผอม
echo "อยู่ในเกณฑ์ผอม ".$count_55to100_20. " คน";
$count_55to100_25 = mysql_result($query,0,'count_55to100_25'); // อายุ 15-18 ปกติ
echo "อยู่ในเกณฑ์ปกติ ".$count_55to100_25. " คน";
$count_55to100_29 = mysql_result($query,0,'count_55to100_29'); // อายุ 15-18 อ้วน
echo "อยู่ในเกณฑ์อ้วน ".$count_55to100_29. " คน";
$count_55to100_mex = mysql_result($query,0,'count_55to100_mex'); // อายุ 15-18 อ้วนมากๆ
echo "อยู่ในเกณฑ์อ้วนมากๆ ".$count_55to100_mex. " คน<br>";
}
?>
</body>
</html>
|
 |
 |
 |
 |
Date :
2010-07-20 22:34:19 |
By :
ยี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตรงบรรทัดนี้
(select count(*) from bmi_db where age>=55 and age<=100 and BMI >=29) as count_55to100_mex, <= ไม่ต้องใส่ , นะ ลองเอา , ออกดูนะ
อืมจริงๆ แล้วตรง _mex จะเขียนว่า _max นะ แต่พิมพ์ผิด เป็น _mex
แต่ก็ไม่ผิดอะไรจะใช้ชื่ออะไรก็ได้ แค่เวลาเรียกใช้ให้ชื่อตรงกันก็พอ
|
 |
 |
 |
 |
Date :
2010-07-20 22:47:31 |
By :
heng |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยัง error เหมือนเดิมคะ
|
 |
 |
 |
 |
Date :
2010-07-20 22:58:49 |
By :
ยี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้ตัวเลขใช่ปะ
|
 |
 |
 |
 |
Date :
2010-07-21 08:42:32 |
By :
aimoomoo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอานี่ตามแก้ให้แล้ว
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>Untitled Document</title>
</head>
<body>
<center>
<form name="form1" method="post" action="">
<select name="select">
<option value="0" selected="selected">โปรดเลือก</option>
<option value="sex">รายงานสถิติตามเพศ</option>
<option value="age">รายงานสถิติตามอายุ</option>
</select>
<input type="submit" name="button" id="button" value="Submit" />
</form>
<br /><br />
<?
$select=$_POST[select];
?>
</center>
<?
$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
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>"; // ผู้ชายทั้งหมด ...
$count_female_all = mysql_result($query,0,'count_female_all'); // ผู้หญิงทั้งหมด
echo "เพศหญิง มี ทั้งหมด ".$count_female_all." คน"; // ผู้หญิงทั้งหมด ...
$count_female_20 = mysql_result($query,0,'count_female_20'); // ผู้หญิงผอม
echo "อยู่ในเกณฑ์ผอม ".$count_female_20." คน"; // ผู้ชายทั้งหมด ...
$count_female_25 = mysql_result($query,0,'count_female_25'); // ผู้หญิงปกติ
echo "อยู่ในเกณฑ์ปกติ ".$count_female_25." คน"; // ผู้ชายทั้งหมด ...
$count_female_29 = mysql_result($query,0,'count_female_29'); // ผู้หญิงอ้วน
echo "อยู่ในเกณฑ์อ้วน ".$count_female_29." คน"; // ผู้ชายทั้งหมด ...
$count_female_mex = mysql_result($query,0,'count_female_mex'); // ผู้หญิงอ้วนมากๆ
echo "อยู่ในเกณฑ์อ้วนมากๆ ".$count_female_mex." คน"; // ผู้ชายทั้งหมด ...
}
##################################################################
if($select=="age"){
echo"เลือก รายงานสถิติตามอายุ <br>";
//1-12
$count_1to12_all = mysql_result($query,0,'count_1to12_all'); // อายุ 0-12 ทั้งหมด
echo "มีอายุอยู่ระหว่าง 0 - 12 มีทั้งหมด ".$count_1to12_all." คน"; //
$count_1to12_20 = mysql_result($query,0,'count_1to12_20'); // อายุ 0-12 ผอม
echo "อยู่ในเกณฑ์ผอม ".$count_1to12_20. " คน";
$count_1to12_25 = mysql_result($query,0,'count_1to12_25'); // อายุ 0-12 ปกติ
echo "อยู่ในเกณฑ์ปกติ ".$count_1to12_25. " คน";
$count_1to12_29 = mysql_result($query,0,'count_1to12_29'); // อายุ 0-12 อ้วน
echo "อยู่ในเกณฑ์อ้วน ".$count_1to12_29. " คน";
$count_1to12_mex = mysql_result($query,0,'count_1to12_mex'); // อายุ 0-12 อ้วนมากๆ
echo "อยู่ในเกณฑ์อ้วนมากๆ ".$count_1to12_mex. " คน <br>";
//13 - 19
$count_13to19_all = mysql_result($query,0,'count_13to19_all'); // อายุ 15-18 ทั้งหมด
echo "มีอายุอยู่ระหว่าง 13 - 19 มีทั้งหมด ".$count_13to19_all." คน"; //
$count_13to19_20 = mysql_result($query,0,'count_13to19_20'); // อายุ 15-18 ผอม
echo "อยู่ในเกณฑ์ผอม ".$count_13to19_20. " คน";
$count_13to19_25 = mysql_result($query,0,'count_13to19_25'); // อายุ 15-18 ปกติ
echo "อยู่ในเกณฑ์ปกติ ".$count_13to19_25. " คน";
$count_13to19_29 = mysql_result($query,0,'count_13to19_29'); // อายุ 15-18 อ้วน
echo "อยู่ในเกณฑ์อ้วน ".$count_13to19_29. " คน";
$count_13to19_mex = mysql_result($query,0,'count_13to19_mex'); // อายุ 15-18 อ้วนมากๆ
echo "อยู่ในเกณฑ์อ้วนมากๆ ".$count_13to19_mex. " คน<br>";
//20 - 54
$count_20to54_all = mysql_result($query,0,'count_20to54_all'); // อายุ 15-18 ทั้งหมด
echo "มีอายุอยู่ระหว่าง 20 - 54 มีทั้งหมด ".$count_20to54_all." คน"; //
$count_20to54_20 = mysql_result($query,0,'count_20to54_20'); // อายุ 15-18 ผอม
echo "อยู่ในเกณฑ์ผอม ".$count_20to54_20. " คน";
$count_20to54_25 = mysql_result($query,0,'count_20to54_25'); // อายุ 15-18 ปกติ
echo "อยู่ในเกณฑ์ปกติ ".$count_20to54_25. " คน";
$count_20to54_29 = mysql_result($query,0,'count_20to54_29'); // อายุ 15-18 อ้วน
echo "อยู่ในเกณฑ์อ้วน ".$count_20to54_29. " คน";
$count_20to54_mex = mysql_result($query,0,'count_20to54_mex'); // อายุ 15-18 อ้วนมากๆ
echo "อยู่ในเกณฑ์อ้วนมากๆ ".$count_20to54_mex. " คน<br>";
//55 - 100
$count_55to100_all = mysql_result($query,0,'count_55to100_all'); // อายุ 15-18 ทั้งหมด
echo "มีอายุอยู่ระหว่าง 55 - 100 มีทั้งหมด ".$count_55to100_all." คน"; //
$count_55to100_20 = mysql_result($query,0,'count_55to100_20'); // อายุ 15-18 ผอม
echo "อยู่ในเกณฑ์ผอม ".$count_55to100_20. " คน";
$count_55to100_25 = mysql_result($query,0,'count_55to100_25'); // อายุ 15-18 ปกติ
echo "อยู่ในเกณฑ์ปกติ ".$count_55to100_25. " คน";
$count_55to100_29 = mysql_result($query,0,'count_55to100_29'); // อายุ 15-18 อ้วน
echo "อยู่ในเกณฑ์อ้วน ".$count_55to100_29. " คน";
$count_55to100_mex = mysql_result($query,0,'count_55to100_mex'); // อายุ 15-18 อ้วนมากๆ
echo "อยู่ในเกณฑ์อ้วนมากๆ ".$count_55to100_mex. " คน<br>";
}
?>
</body>
</html>
|
 |
 |
 |
 |
Date :
2010-07-21 09:00:26 |
By :
aimoomoo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากๆๆคะ สุดยอดๆๆๆๆๆๆๆ เลย
|
 |
 |
 |
 |
Date :
2010-07-21 15:17:44 |
By :
ยี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|