<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
// connect to the server
mysql_connect("localhost:3306", "root", "");
// select the database
mysql_select_db("products");
//COUNT - GROUP BY
$query1 = "select type, COUNT(name) from stationery GROUP BY type";
$result = mysql_query($query1);
while($row = mysql_fetch_array($result))
{
echo "There are " . $row['COUNT(name)'] . " " . $row['type'];
echo "<br/><br/>";
}
//SUM - GROUP BY
$query2 = "select type, SUM(price) from stationery GROUP BY type";
$result2 = mysql_query($query2);
while($row = mysql_fetch_array($result2))
{
echo "The total price for " . $row['type'] . " " . $row['SUM(price)'];
echo "<br/><br/>";
}
//AVG - GROUP BY
$query3 = "select type, AVG(price) from stationery GROUP BY type";
$result3 = mysql_query($query3);
while($row = mysql_fetch_array($result3))
{
echo "The average price for " . $row['type'] . " " . $row['AVG(price)'];
echo "<br/><br/>";
}
// MIN - GROUP BT
$query4 = "select type, MIN(price) from stationery GROUP BY type";
$result4 = mysql_query($query4);
while($row = mysql_fetch_array($result4))
{
echo "The cheapest " . $row['type'] . " " . $row['MIN(price)'];
echo "<br/><br/>";
}
// MAX - GROUP BT
$query5 = "select type, MAX(price) from stationery GROUP BY type";
$result5 = mysql_query($query5);
while($row = mysql_fetch_array($result5))
{
echo "The most expansive " . $row['type'] . " " . $row['MAX(price)'];
echo "<br/><br/>";
}
?>
</body>
</html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
// connect to the server
mysql_connect("localhost:3306", "root", "");
// select the database
mysql_select_db("products");
//COUNT - GROUP BY
$query1 = "select type, COUNT(name) from stationery GROUP BY type";
$result = mysql_query($query1);
while($row = mysql_fetch_array($result))
{
echo "There are " . $row['COUNT(name)'] . " " . $row['type'];
echo "<br/><br/>";
}
//SUM - GROUP BY
$query2 = "select type, SUM(price) from stationery GROUP BY type";
$result2 = mysql_query($query2);
while($row = mysql_fetch_array($result2))
{
echo "The total price for " . $row['type'] . " " . $row['SUM(price)'];
echo "<br/><br/>";
}
//AVG - GROUP BY
$query3 = "select type, AVG(price) from stationery GROUP BY type";
$result3 = mysql_query($query3);
while($row = mysql_fetch_array($result3))
{
echo "The average price for " . $row['type'] . " " . $row['AVG(price)'];
echo "<br/><br/>";
}
// MIN - GROUP BT
$query4 = "select type, MIN(price) from stationery GROUP BY type";
$result4 = mysql_query($query4);
while($row = mysql_fetch_array($result4))
{
echo "The cheapest " . $row['type'] . " " . $row['MIN(price)'];
echo "<br/><br/>";
}
// MAX - GROUP BT
$query5 = "select type, MAX(price) from stationery GROUP BY type";
$result5 = mysql_query($query5);
while($row = mysql_fetch_array($result5))
{
echo "The most expansive " . $row['type'] . " " . $row['MAX(price)'];
echo "<br/><br/>";
}
?>
</body>
</html>
No comments
Post a Comment