BMI 계산기 및 아기성장 발달계산기 문의 채택완료
안녕하세요.
BMI 계산기를 PHP로 표현을 해야하는데..
참고 사이트 : https://www.hanam.go.kr/health/contents.do?key=8926">신체질량지수(BMI) 계산 - 보건소 (hanam.go.kr)
그리고 아기성장발달계산기
https://health.calculate.co.kr/baby-growth-development-calculator">아기성장발달계산기 – 건강 계산기 (calculate.co.kr)
배란일 계산기
http://www.ifatima.co.kr/?menu_code=246#this">커뮤니티 > 배란일 계산기 | 파티마여성병원 (ifatima.co.kr)
https://www.hc.go.kr/06242/06320/06332.web?year=2024&month=8&day=21&jugi=20">배란일계산 | 보건소 (hc.go.kr)
위 사이트처럼 PHP로 구현을 해야하는데 소스보기를 해서 이것저것 시도해보았으나
쉽지 않아서 고수님들께 조언좀 부탁드립니다.
답변 2개
BMI는 체중과 신장(키)을 이용해 개인의 체지방률을 추정하는 방법입니다. BMI 값에 따라 비만도를 평가하며, 다음은 일반적으로 사용되는 판정 기준입니다.
BMI 판정 기준:
- 18.5 미만: 저체중 (Underweight)
- 18.5 - 24.9: 정상 체중 (Normal weight)
- 25.0 - 29.9: 과체중 (Overweight)
- 30.0 - 34.9: 1단계 비만 (Obesity class I)
- 35.0 - 39.9: 2단계 비만 (Obesity class II)
- 40.0 이상: 3단계 비만 (Obesity class III)
예시 코드에서 판정 추가하기
BMI 값을 계산한 후, 이를 기준으로 체중 상태를 판정하는 기능을 추가할 수 있습니다. 다음은 PHP 코드에 판정 기능을 추가한 예시입니다:
</p>
<p><?php
function calculateBMI($weight, $height) {
if ($height <= 0) {
return "Height must be greater than 0.";
}</p>
<p> $bmi = $weight / ($height * $height);
return $bmi;
}</p>
<p>function getBMICategory($bmi) {
if ($bmi < 18.5) {
return "Underweight";
} elseif ($bmi < 24.9) {
return "Normal weight";
} elseif ($bmi < 29.9) {
return "Overweight";
} elseif ($bmi < 34.9) {
return "Obesity class I";
} elseif ($bmi < 39.9) {
return "Obesity class II";
} else {
return "Obesity class III";
}
}</p>
<p>$weight = 70; // 체중 (kg)
$height = 1.75; // 키 (m)</p>
<p>$bmi = calculateBMI($weight, $height);
$category = getBMICategory($bmi);</p>
<p>echo "Your BMI is: " . $bmi . "\n";
echo "You are classified as: " . $category;
?>
</p>
<p>
BMI 계산은 chatGPT 한테 물어보니 잘 알려줍니다.
아기 성장 발달 기준도 잘 알려주는데 기준이 WHO 이긴 하네요. 기준 수정해서 만들면 될거에요.
아기의 성장 발달을 계산하는 간단한 PHP 프로그램을 작성할 수 있습니다. 이 프로그램은 아기의 연령(개월 수), 체중(kg), 신장(cm)을 입력 받아 아기의 성장 상태를 평가하는 기본적인 기능을 제공합니다.
다음은 간단한 아기 성장 발달 계산기 예제 코드입니다:
</p>
<p><?php
function calculateGrowth($ageMonths, $weight, $height) {
// 아기 성장 발달 기준 - 예시 데이터 (WHO 기준)
$growthChart = [
'weight' => [
'0-3' => [2.5, 6], // 0~3개월의 정상 체중 범위 (kg)
'4-6' => [5.5, 8], // 4~6개월의 정상 체중 범위 (kg)
'7-12' => [7, 10], // 7~12개월의 정상 체중 범위 (kg)
'13-24' => [8, 12] // 13~24개월의 정상 체중 범위 (kg)
],
'height' => [
'0-3' => [50, 60], // 0~3개월의 정상 신장 범위 (cm)
'4-6' => [60, 70], // 4~6개월의 정상 신장 범위 (cm)
'7-12' => [70, 80], // 7~12개월의 정상 신장 범위 (cm)
'13-24' => [75, 90] // 13~24개월의 정상 신장 범위 (cm)
]
];</p>
<p> // 아기 나이에 따라 적절한 범위 찾기
if ($ageMonths <= 3) {
$ageGroup = '0-3';
} elseif ($ageMonths <= 6) {
$ageGroup = '4-6';
} elseif ($ageMonths <= 12) {
$ageGroup = '7-12';
} else {
$ageGroup = '13-24';
}</p>
<p> // 체중과 신장 평가
$weightRange = $growthChart['weight'][$ageGroup];
$heightRange = $growthChart['height'][$ageGroup];</p>
<p> $weightStatus = ($weight >= $weightRange[0] && $weight <= $weightRange[1]) ? "Normal" : "Abnormal";
$heightStatus = ($height >= $heightRange[0] && $height <= $heightRange[1]) ? "Normal" : "Abnormal";</p>
<p> return [
'weightStatus' => $weightStatus,
'heightStatus' => $heightStatus
];
}</p>
<p>// 아기 정보 입력 (나이: 개월 수, 체중: kg, 신장: cm)
$ageMonths = 5; // 아기 나이 (개월)
$weight = 7.5; // 아기 체중 (kg)
$height = 67; // 아기 신장 (cm)</p>
<p>$growthStatus = calculateGrowth($ageMonths, $weight, $height);</p>
<p>echo "Age (Months): $ageMonths\n";
echo "Weight (kg): $weight - " . $growthStatus['weightStatus'] . "\n";
echo "Height (cm): $height - " . $growthStatus['heightStatus'] . "\n";
?>
</p>
<p>
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>BMI 계산기</title>
<style>
.container { width: 100%; max-width: 750px; margin: 0 auto; }
.clearfix:after { content: ""; display: table; clear: both; }
.tac { text-align: center; }
.panel3, .panel1 { margin-top: 20px; }
.chart1bmi1 { position: relative; width: 100%; height: 50px; background-color: #f0f0f0; margin-top: 20px; }
.sb1 { position: relative; height: 100%; }
.deco1 { position: absolute; top: 0; bottom: 0; width: 2px; background-color: red; }
.graduated { display: flex; justify-content: space-between; }
.a1 { flex: 1; text-align: center; }
.h3 {
padding: 0 0 0 0px;
background-image: url(../../img/lib/h3bg2.png);
background-position: 0 .25em;
color: #007e4c;
font-weight: 400;
font-size: 1.275em;
}
.h4 {
font-size: 1.25em;
padding: 0;
color: #125fac;
font-weight: 400;
margin: 1.3em 0 1em;
}
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}
.container {
width: 80%;
margin: 20px auto;
background: #fff;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.form-group {
margin-bottom: 15px;
}
label {
xdisplay: block;
margin-bottom: 5px;
font-weight: bold;
}
input[type="number"], select {
width: 100%;
padding: 8px;
margin-bottom: 10px;
border: 1px solid #ddd;
border-radius: 4px;
}
button {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
border-radius: 4px;
}
.result {
margin-top: 20px;
}
.panel1 {
text-align: center;
font-size: 18px;
}
.fsXXL {
font-size: 24px;
margin-bottom: 20px;
}
.chart1bmi1 {
position: relative;
height: 60px;
background: #e0e0e0;
border-radius: 5px;
overflow: hidden;
}
.chart1bmi1 .sb1 {
position: relative;
height: 100%;
}
.chart1bmi1 .bmi1value {
font-size: 18px;
font-weight: bold;
}
.chart1bmi1 .deco1 {
position: absolute;
top: 0;
height: 100%;
background: #4CAF50;
width: 2px;
transition: left 0.3s ease;
}
.chart1bmi1 .area, .chart1bmi1 .graduated {
position: absolute;
top: 0;
width: 100%;
height: 100%;
}
.chart1bmi1 .area span, .chart1bmi1 .graduated span {
position: absolute;
font-size: 12px;
font-weight: bold;
}
.em1 {
color: #e00;
}
.em4 {
color: #080;
}
.chart1bmi1 .area .a1 { left: 0%; }
.chart1bmi1 .area .a2 { left: 20%; }
.chart1bmi1 .area .a3 { left: 24%; }
.chart1bmi1 .area .a4 { left: 30%; }
.chart1bmi1 .graduated .m1 { left: 0%; background: #09f url('https://www.hc.go.kr/_res/portal/img/lib1cp1/b.ffffff.opacity.20.pattern1.png');}
.chart1bmi1 .graduated .m2 { left: 20%; background: #0a0 url('https://www.hc.go.kr/_res/portal/img/lib1cp1/b.ffffff.opacity.20.pattern2.png');}
.chart1bmi1 .graduated .m3 { left: 24%; background: #b80 url('https://www.hc.go.kr/_res/portal/img/lib1cp1/b.ffffff.opacity.20.pattern3.png');}
.chart1bmi1 .graduated .m4 { left: 30%; background: #f55 url('https://www.hc.go.kr/_res/portal/img/lib1cp1/b.ffffff.opacity.20.pattern2.png');}
.bmi-table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
font-size: 1em;
text-align: center;
}
.bmi-table th, .bmi-table td {
border: 1px solid #dddddd;
padding: 12px 15px;
}
.bmi-table th {
background-color: #f2f2f2;
}
.bmi-table caption {
font-weight: bold;
margin-bottom: 10px;
}
.bmi-table .tal {
text-align: left;
}
</style>
</head>
<body>
<div class="container clearfix">
<h3 class="hb1 h3">신체질량지수(BMI) : 신장과 체중으로 알아보는 자신의 비만도</h3>
<p>자신의 신체계측지수를 입력한 후 확인을 클릭하시면 신체질량지수(BMI)에 의한 비만도를 알 수 있습니다.</p>
<!-- panel3 -->
<div class="panel3 clearfix">
<!-- form -->
<form id="bmiForm" name="bmiForm" action="" method="post">
<fieldset class="mg0">
<legend class="blind"><strong class="h1">비만도 계산</strong></legend>
<span class="nowrap">
<span class="label">성별</span>
<input id="bmiSex1" name="bmiSex" type="radio" value="M" <?php echo isset($_POST['bmiSex']) && $_POST['bmiSex'] == 'M' ? 'checked' : ''; ?>><label for="bmiSex1">남</label>
<input id="bmiSex2" name="bmiSex" type="radio" value="F" <?php echo isset($_POST['bmiSex']) && $_POST['bmiSex'] == 'F' ? 'checked' : ''; ?>><label for="bmiSex2">여</label>
</span>
<span class="nowrap">
<label for="bmiHeight" class="label">신장 </label>
<input id="bmiHeight" name="bmiHeight" class="tar" type="text" value="<?php echo isset($_POST['bmiHeight']) ? $_POST['bmiHeight'] : ''; ?>" size="10"> cm
</span>
<span class="nowrap">
<label for="bmiWeight" class="label">체중 </label>
<input id="bmiWeight" name="bmiWeight" class="tar" title="신장" type="text" value="<?php echo isset($_POST['bmiWeight']) ? $_POST['bmiWeight'] : ''; ?>" size="10"> kg
</span>
<span class="nowrap">
<button type="submit" value="submit" class="button submit w100-for-small">계산하기</button>
</span>
</fieldset>
</form>
<!-- /form -->
</div>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$height = $_POST['bmiHeight'] / 100;
$weight = $_POST['bmiWeight'];
$bmi = $weight / ($height * $height);
$bmi = round($bmi, 2);
if ($_POST['bmiSex'] == 'M') {
$averageWeight = round($height * $height * 22);
} else {
$averageWeight = round($height * $height * 21);
}
$bmiCategory = '';
$deco1left = 0;
if ($bmi < 20) {
$bmiCategory = '저체중';
$deco1left = ($bmi / 20) * 25;
} elseif ($bmi >= 20 && $bmi < 24) {
$bmiCategory = '정상';
$deco1left = 25 + (($bmi - 20) / 4) * 25;
} elseif ($bmi >= 24 && $bmi < 30) {
$bmiCategory = '과체중';
$deco1left = 50 + (($bmi - 24) / 6) * 25;
} else {
$bmiCategory = '비만';
$deco1left = 75 + (($bmi - 30) / 70) * 25;
}
$deco1left .= '%';
?>
<div class="panel1 clearfix tac">
<p class="fsXXL">BMI측정결과 : 신체질량지수(BMI)는 <b class="em1"><?php echo $bmi; ?></b> 로 <b class="em4">"<?php echo $bmiCategory; ?>"</b> 입니다. 평균체중은 <b class="em4"><?php echo $averageWeight; ?></b> Kg 입니다.</p>
<!-- chart1bmi1 -->
<div class="chart1bmi1">
<strong class="blind">BMI Chart</strong>
<div class="sb1">
<b class="blind">BMI</b>
<span class="bmi1value blind"><?php echo $bmi; ?></span>
<i class="deco1" style="left: <?php echo $deco1left; ?>;"><!-- ▼ --></i>
</div>
<div class="area">
<b class="blind">구간</b>
<span class="a1 m1">저체중 <span class="blind">(0 이상 20 미만)</span></span>
<span class="a1 m2">정상 <span class="blind">(20 이상 24 미만)</span></span>
<span class="a1 m3">과체중 <span class="blind">(24 이상 30 미만)</span></span>
<span class="a1 m4">비만 <span class="blind">(30 이상 100 이하)</span></span>
</div>
<div class="graduated">
<b class="blind">눈금</b>
<span class="a1 m1">0</span>
<span class="a1 m2">20</span>
<span class="a1 m3">24</span>
<span class="a1 m4">30 이상</span>
</div>
</div>
<!-- /chart1bmi1 -->
</div>
<!-- /panel1 -->
<?php
}
?>
<!-- /panel3 -->
<h4 class="hb1 h4">신체질량지수(Body Mass Index:BMI,카우프지수)에 의한 비만도 계산법</h4>
<p>비만의 판정의 올바른 지표는 체중이 아니라 체지방량이므로 몸의 지방량을 직접 측정하는 것이 이상적이나 이것은 기술적인 어려움이 있기 때문에 표준체중, 신체질량지수 등 체지방량을 간접적으로 측정하는 방법이 일반적이다.</p>
<table class="bmi-table">
<caption>BMI 에 의한 비만도 계산법</caption>
<thead>
<tr>
<th scope="col">항목</th>
<th scope="col">구분</th>
<th scope="col">내용</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">계산식</th>
<td colspan="2">신체질량지수(BMI) = 체중(kg) / [신장(m)]<sup>2</sup></td>
</tr>
<tr>
<th scope="row" rowspan="4">판정기준</th>
<th scope="row">저체중</th>
<td>20 미만</td>
</tr>
<tr>
<th scope="row">정상</th>
<td>20 - 24</td>
</tr>
<tr>
<th scope="row">과체중</th>
<td>25 - 29</td>
</tr>
<tr>
<th scope="row">비만</th>
<td>30 이상</td>
</tr>
<tr>
<th scope="row">장단점</th>
<td colspan="2" class="tal">표준체중보다는 체지방을 비교적 정확하게 반영할 수 있으면서도 매우 간단히 계산하여 판정할 수 있다.</td>
</tr>
</tbody>
</table>
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
계산하기 하면 결과에 표형식으로 저체중 정상 과체중 비만 이 항목이
제대로 표현이 안되는데...어디를 봐야할까요?
https://www.hc.go.kr/06242/06320/06334.web?avlVal=71&bmiVal=21.6&bmiSex=M&bmiHeight=180&bmiWeight=70