Esempio n. 1
0
function print_detail_statistic($connection, $type, $user)
{
    #Получаем список значений и их количество
    $query = "SELECT {$type} FROM Costs AND User = {$user}";
    $result = mysqli_query($connection, $query) or die(mysqli_error($connection));
    while ($row = mysqli_fetch_array($result)) {
        if (@$list[$row[0]]) {
            $list[$row[0]]++;
        } else {
            $list[$row[0]] = 1;
            echo "<h4>{$row['0']}</h4>";
            print_sum($connection, 'Costs', $user, 'Price', '2', "AND Buy_type = \"{$row['0']}\"");
        }
    }
    echo "<h4 class='center'>Суммарно</h4>";
    echo "<table>";
    echo "<tr>";
    echo "<th>Тип</th>";
    echo "<th>Сумма</th>";
    echo "<th>Количество</th>";
    echo "</tr>";
    foreach ($list as $key => $value) {
        $query = "SELECT SUM(Price) FROM Costs WHERE {$type} = \"{$key}\" AND User = {$user}";
        $result = mysqli_query($connection, $query) or die(mysqli_error($connection));
        $row = mysqli_fetch_array($result);
        echo "<tr>";
        echo "<td>{$key}</td>";
        echo "<td class='right'>{$row['0']}</td>";
        echo "<td class='right'>{$value}</td>";
        echo "</tr>";
    }
    echo "</table>";
}
Esempio n. 2
0
	<link rel="stylesheet" type="text/css" href="../css/style.css">
	<title>Статистика</title>
	<?php 
include '../scripts/header.php';
?>
</head>
<body>

	<div class="table">
	<h1>Расходы</h1>
		<?php 
print_sum($connection, 'Costs', $user, 'Price', '2');
?>
	<h1>Доходы</h1>	
		<?php 
print_sum($connection, 'Income', $user, 'Quantity', '2');
?>
	<h1>Детально</h1>
		<?php 
print_detail_statistic($connection, 'Buy_type', $user);
?>
	</div>


</body>

<div class="h_footer"></div>
<?php 
include '../scripts/footer.php';
?>