<?php
// Эта строчка — где-то в другом файле — где в данный момент инициализируется соединение с БД
$db = new PDO('mysql:dbname=testdb;host=127.0.0.1', 'username', 'password');
$sth = $db->prepare("
SELECT
t.`id`,
DATE_FORMAT(rt.`data`, '%d.%m.%Y') remont_date,
ma.`name` marka,
mo.`name` model,
t.`serial`,
rt.`work_id`,
rt.`sum`
FROM `tech` t
LEFT JOIN `remont_tech` rt ON rt.`tech_id` = t.`id` AND rt.`status` <> 'delete'
LEFT JOIN `marka` ma ON ma.`marka` = t.`marka`
LEFT JOIN `model` mo ON mo.`id` = t.`model`
WHERE
t.`user` = ? AND
TIMESTAMPDIFF(DAY, rt.`data`, NOW()) BETWEEN 0 AND 30
ORDER BY rt.`data` DESC
");
$sth->execute(array($myrow['id']));
$result = $sth->fetchAll();
?>
<table>
<tr>
<th>№</th>
<th>Дата</th>
<th>Оборудование</th>
<th>Проделанная работа</th>
<th>Сумма</th>
</tr>
<?php if (!count($result)) : ?>
<tr>
<td>0</td>
<td colspan="4">Ничего не найдено.</td>
</tr>
<?php else : ?>
<?php $summ = 0; ?>
<?php foreach ($result as $key => $row) : ?>
<tr>
<td><?= $key+1 ?></td>
<td><?= $row['remont_date'] ?></td>
<td><?= sprintf('%s %s(%s)', $row['marka'], $row['model'], $row['serial']) ?></td>
<td><?= $row['work_id'] ?></td>
<td><?= number_format($row['sum'], 0, ',', ' ') ?> руб.</td>
</tr>
<?php $summ += $row['sum']; ?>
<?php endforeach; ?>
<tr>
<td colspan="3"></td>
<td><b>ИТОГО:</b></td>
<td><b><?= number_format($summ, 0, ',', ' ') ?> руб.</b></td>
</tr>
<?php endif; ?>
</table>
SELECT `rt`.`sum` AS `sum`, `rt`.`work_id` AS `work_id`, `t`.`serial` AS serial, `mk`.`name` AS `marka`,
`md`.`name` AS `model`, DATE_FORMAT(`rt`.`data`, '%d.%m.%Y') AS `data`
FROM `remont_tech` AS `rt`
LEFT JOIN `tech` AS `t` ON `rt`.`tech_id` = `t`.`id`
LEFT JOIN `marka` AS `mk` ON `t`.`marka` = `mk`.`id`
LEFT JOIN `model` AS `md` ON `t`.`model` = `md`.`id`
WHERE `rt`.`tech_id` = '$techs_id'
AND `rt`.`status` != 'delete'
AND TO_DAYS(NOW()) - TO_DAYS(`rt`.`data`) <= 30
ORDER BY `rt`.`data`
$tech = mysql_query("SELECT SUM(`rt`.`sum`) ".
" FROM `tech` AS `t` ".
" INNER JOIN `remont_tech` AS `rt` ON `t`.`id` = `rt`.`tech_id` ".
" WHERE `t`.`tech_cat` = '".mysql_real_escape_string($cat_id)."' ".
" AND `t`.`status` = 'normal'");
if ($techs = mysql_fetch_array($tech))
$summa = $techs[0];
"SELECT SUM(remont_tech.sum)
FROM tech
INNER JOIN remont_tech ON remont_tech.id = tech.tech_cat
WHERE tech_cat= ".$cat_id." AND status='normal'"
$res = mysql_query("SELECT model FROM tech WHERE tech_cat='{$cat_id}'");
$models = array();
while ( $row = mysql_fetch_assoc($res) ) {
$models[] = $row['model'];
}
print_r($models);
print_r(array_count_values($models));
echo "<center><table style='border-collapse :collapse; border-spacing :0;' border=1>\n";
echo " <tr><td width ='20'>№</td><td width='50'>Дата</td><td width='200'>Оборудование</td><td width='150'>Проделанная работа</td> <td width='80'>Сумма</td></tr>\n";
$tehas = mysql_query("SELECT *, DATE_FORMAT(data,'%d.%m.%Y') As data FROM remont_tech WHERE status = 'nomoney' WHERE user = '".intval($myrow['id'])."' ORDER BY data");
$i = 0;
$totalPrice = 0;
foreach($tehas as $tech){
echo "<tr><td>".$i++."</td><td>".$tech['data']."</td><td>".$tech['marka'].' '.$tech['model'].'('.$tech['serial'].')</td><td>'.$tech['work_id'].'</td><td>'.$tech['sum'].' Руб.</td><tr>';
$totalPrice += $tech['sum'];
}
echo"<tr><td COLSPAN=1><b>ИТОГО</b></td><td></td><td></td><td></td><td><b>".$totalPrice." Руб.</b></td></tr>";
echo "</table></center>\n";