-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.php
More file actions
29 lines (23 loc) · 859 Bytes
/
common.php
File metadata and controls
29 lines (23 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
//https://stackoverflow.com/questions/12235595/find-most-frequent-value-in-sql-column
$conn_cart = mysqli_connect($l, $u, $p, $d);
$sql="SELECT `name`
FROM `tbl`
GROUP BY `name`
ORDER BY COUNT(*) DESC";
$result=mysqli_query($conn_cart, $sql);
$common = $result->fetch_array(MYSQLI_NUM);
$countAll="select count(*) from tbl";
$countAll=mysqli_query($conn_cart, $countAll);
$count = $countAll->fetch_array(MYSQLI_NUM);
//echo $count[0];
$countCommon="select count(*) from tbl where name='$common[0]' ";
$countCommon=mysqli_query($conn_cart, $countCommon);
$countCommon = $countCommon->fetch_array(MYSQLI_NUM);
// echo $countCommon[0];
echo $common[0];
echo(" <br> ");
echo(" was purchased ");
echo round($countCommon[0] / $count[0]*100);
echo("% of all orders. " );
?>