Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
5 views15 pages

Codephp 1.0

The document is a PHP script that connects to a MySQL database to retrieve and display child and mother information, including demographics and health data. It generates various charts using Highcharts to visualize data such as gender distribution, age groups, blood types, birth defects, and breastfeeding practices. The script includes error handling and sets character encoding for proper data display.

Uploaded by

caohoa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views15 pages

Codephp 1.0

The document is a PHP script that connects to a MySQL database to retrieve and display child and mother information, including demographics and health data. It generates various charts using Highcharts to visualize data such as gender distribution, age groups, blood types, birth defects, and breastfeeding practices. The script includes error handling and sets character encoding for proper data display.

Uploaded by

caohoa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 15

<?

php

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "ntttuyen3001";

$conn = new mysqli($servername, $username, $password, $dbname);

if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
mysqli_query($conn,"SET CHARACTER SET 'utf8'");
mysqli_query($conn,"SET SESSION collation_connection ='utf8_unicode_ci'");

error_reporting(0);
ini_set('display_errors', 0);

// error_reporting(E_ALL);
// ini_set('display_errors', '1');
?>

<?php

// Retrieve data from the database using an SQL query.

$sql_male = "SELECT * FROM `personal_information` WHERE gender = 'boy' ";


$query_male = $conn->query($sql_male);
$rowcount_male =mysqli_num_rows($query_male);

$sql_female = "SELECT * FROM `personal_information` WHERE gender = 'girl' ";


$query_female = $conn->query($sql_female);
$rowcount_female =mysqli_num_rows($query_female);

$sql_birthdefects_yes = "SELECT * FROM `personal_information` WHERE


birthdefects = 'yes' ";
$query_birthdefects_yes = $conn->query($sql_birthdefects_yes);
$rowcount_birthdefects_yes =mysqli_num_rows($query_birthdefects_yes);

$sql_birthdefects_no = "SELECT * FROM `personal_information` WHERE


birthdefects = 'no' ";
$query_birthdefects_no = $conn->query($sql_birthdefects_no);
$rowcount_birthdefects_no =mysqli_num_rows($query_birthdefects_no);

$total_children = $rowcount_birthdefects_no + $rowcount_birthdefects_no;

$sql_age_in_month_1 = "SELECT * FROM `personal_information` WHERE


ageinmonth = '0-5' ";
$query_age_in_month_1 = $conn->query($sql_age_in_month_1);
$rowcount_age_in_month_1 =mysqli_num_rows($query_age_in_month_1);
$sql_age_in_month_2 = "SELECT * FROM `personal_information` WHERE
ageinmonth = '6-23' ";
$query_age_in_month_2 = $conn->query($sql_age_in_month_2);
$rowcount_age_in_month_2 =mysqli_num_rows($query_age_in_month_2);

$sql_age_in_month_3 = "SELECT * FROM `personal_information` WHERE


ageinmonth = '24-35' ";
$query_age_in_month_3 = $conn->query($sql_age_in_month_3);
$rowcount_age_in_month_3 =mysqli_num_rows($query_age_in_month_3);

$sql_age_in_month_4 = "SELECT * FROM `personal_information` WHERE


ageinmonth = '36-47' ";
$query_age_in_month_4 = $conn->query($sql_age_in_month_4);
$rowcount_age_in_month_4 =mysqli_num_rows($query_age_in_month_4);

$sql_age_in_month_5 = "SELECT * FROM `personal_information` WHERE


ageinmonth = '48-60' ";
$query_age_in_month_5 = $conn->query($sql_age_in_month_5);
$rowcount_age_in_month_5 =mysqli_num_rows($query_age_in_month_5);

$sql_blood_group_a = "SELECT * FROM `personal_information` WHERE


bloodgroup = 'A' ";
$query_blood_group_a = $conn->query($sql_blood_group_a);
$rowcount_blood_group_a =mysqli_num_rows($query_blood_group_a);

$sql_blood_group_b = "SELECT * FROM `personal_information` WHERE


bloodgroup = 'B' ";
$query_blood_group_b = $conn->query($sql_blood_group_b);
$rowcount_blood_group_b=mysqli_num_rows($query_blood_group_b);

$sql_blood_group_ab = "SELECT * FROM `personal_information` WHERE


bloodgroup = 'AB' ";
$query_blood_group_ab = $conn->query($sql_blood_group_ab);
$rowcount_blood_group_ab =mysqli_num_rows($query_blood_group_ab);

$sql_blood_group_o = "SELECT * FROM `personal_information` WHERE


bloodgroup = 'O' ";
$query_blood_group_o = $conn->query($sql_blood_group_o);
$rowcount_blood_group_o =mysqli_num_rows($query_blood_group_o);

$sql_exclusiveBreastfeeding_no = "SELECT * FROM `personal_information`


WHERE exclusiveBreastfeeding = 'no' ";
$query_exclusiveBreastfeeding_no = $conn-
>query($sql_exclusiveBreastfeeding_no);
$rowcount_exclusiveBreastfeeding_no
=mysqli_num_rows($query_exclusiveBreastfeeding_no);

$sql_exclusiveBreastfeeding_yes = "SELECT * FROM `personal_information`


WHERE exclusiveBreastfeeding = 'yes' ";
$query_exclusiveBreastfeeding_yes = $conn-
>query($sql_exclusiveBreastfeeding_yes);
$rowcount_exclusiveBreastfeeding_yes
=mysqli_num_rows($query_exclusiveBreastfeeding_yes);

$sql_mothereducation_1 = "SELECT * FROM `personal_information` WHERE


mothereducation = 'no formal education' ";
$query_mothereducation_1 = $conn->query($sql_mothereducation_1);
$rowcount_mothereducation_1 =mysqli_num_rows($query_mothereducation_1);

$sql_mothereducation_2 = "SELECT * FROM `personal_information` WHERE


mothereducation = 'Primary' ";
$query_mothereducation_2 = $conn->query($sql_mothereducation_2);
$rowcount_mothereducation_2 =mysqli_num_rows($query_mothereducation_2);

$sql_mothereducation_3 = "SELECT * FROM `personal_information` WHERE


mothereducation = 'secondary' ";
$query_mothereducation_3 = $conn->query($sql_mothereducation_3);
$rowcount_mothereducation_3 =mysqli_num_rows($query_mothereducation_3);

$sql_mothereducation_4 = "SELECT * FROM `personal_information` WHERE


mothereducation = 'high school and above' ";
$query_mothereducation_4 = $conn->query($sql_mothereducation_4);
$rowcount_mothereducation_4 =mysqli_num_rows($query_mothereducation_4);

$sql_motheremployment_1 = "SELECT * FROM `personal_information` WHERE


motheremployment = 'government officer' ";
$query_motheremployment_1 = $conn->query($sql_motheremployment_1);
$rowcount_motheremployment_1
=mysqli_num_rows($query_motheremployment_1);

$sql_motheremployment_2 = "SELECT * FROM `personal_information` WHERE


motheremployment = 'private field' ";
$query_motheremployment_2 = $conn->query($sql_motheremployment_2);
$rowcount_motheremployment_2
=mysqli_num_rows($query_motheremployment_2);

$sql_motheremployment_3 = "SELECT * FROM `personal_information` WHERE


motheremployment = 'farming and rising livestocky' ";
$query_motheremployment_3 = $conn->query($sql_motheremployment_3);
$rowcount_motheremployment_3
=mysqli_num_rows($query_motheremployment_3);

$sql_motheremployment_4 = "SELECT * FROM `personal_information` WHERE


motheremployment = 'Housewives' ";
$query_motheremployment_4 = $conn->query($sql_motheremployment_4);
$rowcount_motheremployment_4
=mysqli_num_rows($query_motheremployment_4);

$sql_motheremployment_5 = "SELECT * FROM `personal_information` WHERE


motheremployment = 'Other' ";
$query_motheremployment_5 = $conn->query($sql_motheremployment_5);
$rowcount_motheremployment_5
=mysqli_num_rows($query_motheremployment_5);

$sql_motheremployment_6 = "SELECT * FROM `personal_information` WHERE


motheremployment = 'Unemployed' ";
$query_motheremployment_6 = $conn->query($sql_motheremployment_6);
$rowcount_motheremployment_6
=mysqli_num_rows($query_motheremployment_6);

?>
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> Dashboard </title>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
<script src="https://code.highcharts.com/highcharts-3d.js"></script>
</head>

<body>

<a href="hoa01022025.php" > <img src="img/returntohome.png" width="150px"


height="120px"> </a>

<h1> Child Information </h1>

<div id="container"></div>
<div id="container_2"></div>
<div id="container_3"></div>
<div id="container_4"></div>
<div id="container_5"></div>
<h2> Mother Information </h2>
<div id="container_6"></div>
<div id="container_7"></div>
<!-- Create a pie chart -->
<script>
Highcharts.chart('container', {
chart: {
type: 'pie'
},
title: {
text: 'Gender'
},
tooltip: {
valueSuffix: ''
},

plotOptions: {
series: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: [{
enabled: true,
distance: 20
}, {
enabled: true,
distance: -40,
format: '{point.y:.0f} ',
style: {
fontSize: '1.2em',
textOutline: 'none',
opacity: 0.7
},
filter: {
operator: '>',
property: 'Gender',
value: 10
}
}]
}
},
series: [{
name: 'Gender',
colorByPoint: true,
data: [{
name: 'Male',
y: <?php echo $rowcount_male;?>
},
{
name: 'Female',
sliced: true,
selected: true,
y: <?php echo $rowcount_female;?>
}

]
}]
});
</script>
<!-----Create age in month--->

<script>
Highcharts.chart('container_2', {
chart: {
type: 'bar'
},
title: {
text: 'Age in month'
},

xAxis: {
categories: ['0-5', '6-23', '24-35', '36-47', '48-60'],
crosshair: true,
accessibility: {
description: 'Age in month'
}
},
yAxis: {
min: 0,
title: {
text: ' '
}
},
tooltip: {
valueSuffix: ' '
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [

{
name: 'Age in month',
data: [<?php echo $rowcount_age_in_month_1;?> , <?php echo
$rowcount_age_in_month_2;?> ,
<?php echo $rowcount_age_in_month_3;?> , <?php echo
$rowcount_age_in_month_4;?>,
<?php echo $rowcount_age_in_month_5;?>]
}
]
});

</script>

<!-- Create a column chart for blood group -->


<script>
Highcharts.chart('container_3', {
chart: {
type: 'column'
},
title: {
text: 'Blood Group'
},

xAxis: {
categories: ['A', 'B', 'AB', 'O'],
crosshair: true,
accessibility: {
description: 'Blood Group'
}
},
yAxis: {
min: 0,
title: {
text: ' '
}
},
tooltip: {
valueSuffix: ' '
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [

{
name: 'Blood Group',
data: [<?php echo $rowcount_blood_group_a;?> , <?php echo
$rowcount_blood_group_b;?> , <?php echo $rowcount_blood_group_ab;?> , <?php
echo $rowcount_blood_group_o;?> ]
}
]
});

</script>
<!-----create birth defects--->

<!DOCTYPE html>
<html>
<head>
<script src="https://code.highcharts.com/highcharts.js"></script>
</head>
<body>

<!-- Vùng hiển thị biểu đồ -->


<div id="container_4" style="width: 600px; height: 400px;"></div>

<script>
Highcharts.chart('container_4', {
chart: {
type: 'pie',
custom: {},
events: {
render() {
const chart = this,
series = chart.series[0];
let customLabel = chart.options.chart.custom.label;

if (!customLabel) {
customLabel = chart.options.chart.custom.label =
chart.renderer.label(
'Total of children<br/>' +
'<strong><?php echo $total_children; ?></strong>'
)
.css({
color: '#000',
textAnchor: 'middle'
})
.add();
}

const x = series.center[0] + chart.plotLeft,


y = series.center[1] + chart.plotTop -
(customLabel.attr('height') / 2);

customLabel.attr({
x,
y
});

// Set font size based on chart diameter


customLabel.css({
fontSize: `${series.center[2] / 12}px`
});
}
}
},
accessibility: {
point: {
valueSuffix: '%'
}
},
title: {
text: 'Birth detects'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.0f}%</b>'
},
legend: {
enabled: true
},
plotOptions: {
series: {
allowPointSelect: true,
cursor: 'pointer',
borderRadius: 8,
dataLabels: [{
enabled: true,
distance: 20,
format: '{point.name}'
}, {
enabled: true,
distance: -15,
format: '{point.percentage:.0f}%',
style: {
fontSize: '0.9em'
}
}],
showInLegend: true
}
},
series: [{
name: 'Prevelence',
colorByPoint: true,
innerSize: '75%',
data: [{
name: 'Yes',
y: <?php echo $rowcount_birthdefects_yes; ?> // Số trẻ có dị tật
}, {
name: 'No',
y: <?php echo $rowcount_birthdefects_no; ?> // Số trẻ không có dị tật
}]
}]
});
</script>

</body>
</html>

<!-----create exclusive breastfeeding--->


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Exclusive Breastfeeding</title>
<script src="https://code.highcharts.com/highcharts.js"></script>
</head>
<body>
<div id="container_5" style="width: 100%; height: 400px;"></div>

<script>
(function (H) {
H.seriesTypes.pie.prototype.animate = function (init) {
const series = this,
chart = series.chart,
points = series.points,
{ animation } = series.options,
{ startAngleRad } = series;

function fanAnimate(point, startAngleRad) {


const graphic = point.graphic,
args = point.shapeArgs;

if (graphic && args) {


graphic
.attr({
start: startAngleRad,
end: startAngleRad,
opacity: 1
})
.animate({
start: args.start,
end: args.end
}, {
duration: animation.duration / points.length
}, function () {
if (points[point.index + 1]) {
fanAnimate(points[point.index + 1], args.end);
}
if (point.index === series.points.length - 1) {
series.dataLabelsGroup.animate({
opacity: 1
}, void 0, function () {
points.forEach(point => {
point.opacity = 1;
});
series.update({
enableMouseTracking: true
}, false);
chart.update({
plotOptions: {
pie: {
innerSize: '40%',
borderRadius: 8
}
}
});
});
}
});
}
}

if (init) {
points.forEach(point => {
point.opacity = 0;
});
} else {
fanAnimate(points[0], startAngleRad);
}
};
}(Highcharts));

Highcharts.chart('container_5', {
chart: {
type: 'pie'
},
title: {
text: 'Exclusive Breastfeeding'
},
subtitle: {
text: 'Prevalence of Exclusive Breastfeeding'
},
tooltip: {
headerFormat: '',
pointFormat:
'<span style="color:{point.color}">\u25cf</span> ' +
'{point.name}: <b>{point.percentage:.1f}%</b>'
},
accessibility: {
point: {
valueSuffix: '%'
}
},
plotOptions: {
pie: {
allowPointSelect: true,
borderWidth: 2,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b><br>{point.percentage}%',
distance: 20
}
}
},
series: [{
enableMouseTracking: false,
animation: {
duration: 2000
},
colorByPoint: true,
data: [{
name: 'Yes',
y: <?php echo $rowcount_exclusiveBreastfeeding_yes; ?> // Số trẻ có dị
tật
}, {
name: 'No',
y: <?php echo $rowcount_exclusiveBreastfeeding_no; ?> // Số trẻ không
có dị tật
}]
}]
});
</script>
</body>
</html>

<!-- Thêm container để Highcharts vẽ biểu đồ -->


<div id="container_6"></div>

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-3d.js"></script>

<script>
Highcharts.chart('container_6', {
chart: {
type: 'pie',
options3d: {
enabled: true,
alpha: 45
}
},
title: {
text: 'Mother Education'
},
subtitle: {
text: '3D donut in Highcharts'
},
plotOptions: {
pie: {
innerSize: 100,
depth: 45
}
},
series: [{
name: 'Number of Mothers',
data: [
{
name: 'No formal education',
y: <?php echo $rowcount_mothereducation_1; ?> // trình độ học vấn 1
},
{
name: 'Primary',
y: <?php echo $rowcount_mothereducation_2; ?> // trình độ học vấn 2
},
{
name: 'Secondary',
y: <?php echo $rowcount_mothereducation_3; ?> // trình độ học vấn 3
},
{
name: 'High school and above',
y: <?php echo $rowcount_mothereducation_4; ?> // trình độ học vấn 4
}
]
}]
});
</script>

<script>
<h7> Mother Employment </h7>

<!-- Thêm container để vẽ biểu đồ --->

<div id="container_7"></div>

<!-- Nhúng thư viện Highcharts -->


<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-3d.js"></script>

<script>
Highcharts.chart('container_7', {
chart: {
type: 'cylinder',
options3d: {
enabled: true,
alpha: 15,
beta: 15,
depth: 50,
viewDistance: 25
}
},
title: {
text: 'Mother Employment'
},
subtitle: {
text:
},
xAxis: {
categories: [
'government officer', 'private field', 'farming and rising livestocky',
'Housewives', 'Other', 'Unemployed'
],
title: {
text: 'Mother Employment'
},
labels: {
skew3d: true
}
},
yAxis: {
title: {
margin: 20,
text: 'Number'
},
labels: {
skew3d: true
}
},
tooltip: {
headerFormat:
pointFormat:
},
plotOptions: {
series: {
depth: 25,
colorByPoint: true
}
},
series: [{
name: 'Mother Employment',
showInLegend: false,
data: [
<?php echo $rowcount_motheremployment_1; ?>,
<?php echo $rowcount_motheremployment_2; ?>,
<?php echo $rowcount_motheremployment_3; ?>,
<?php echo $rowcount_motheremployment_4; ?>,
<?php echo $rowcount_motheremployment_5; ?>,
<?php echo $rowcount_motheremployment_6; ?>,

]
}]
});
</script>
</body>

</html>

You might also like