PHP
- 10 ответов
- 0 вопросов
5
Вклад в тег
foreach($_POST["pokazaniya"] as $key=>$value) {
//в $value - показания
}
while ($data = mysql_fetch_array($qr_result)) {
echo '<tr>';
echo '<td><input type="text" name="devices['.$data['device_id'].'][street]" value="' . $data['street'] . '" maxlength="10" form="myform" disabled></td>';
echo '<td><input type="text" name="devices['.$data['device_id'].'][house_number]" value="' . $data['house_number'] . '" maxlength="10" form="myform" disabled></td>';
echo '<td><input type="text" name="devices['.$data['device_id'].'][appartment_number]" value="' . $data['app_number'] . '" maxlength="10" form="myform" disabled></td>';
echo '<td><input type="text" name="devices['.$data['device_id'].'][device_id]" value="' . $data['device_id'] . '" maxlength="10" form="myform" disabled></td></td>';
echo '<td><input type="text" name="devices['.$data['device_id'].'][description]" value="' . $data['description'] . '" maxlength="10" form="myform" disabled></td>';
echo '<td><input type="number" name="devices['.$data['device_id'].'][old_meterage]" value="' . $data['old_meterage'] . '" maxlength="10" form="myform" disabled></td>';
echo '<td><input type="text" name="devices['.$data['device_id'].'][new_meterage]" maxlength="10" form="myform"></td></tr>';
}
$_POST = [
'devices' =>
[
'1234567' => //<--ID счётчика
[
'street' => '',
'house_number' => '',
'appartment_number' => '',
'device_id' => '',
'description' => '',
'old_meterage' => '',
'new_meterage' => '',
]
]
]
foreach($_POST['devices'] as $device_id=>$device_data) {
// В переменной $device_id - айдишник вашего прибора учёта.
// В переменной $device_data - все поля формы для этого конкретного прибора
}
$query = mysql_query("SELECT * FROM `$table` SORT BY street, house_number, app_number ");
// Затем в цикле разбираем запрос, и формируем XML
$xml = '<?xml version="1.0" encoding="utf-8"?>' . PHP_EOL;
$prev_street = null;
$prev_house = null;
$prev_app = null;
$prev_acc = null;
while ($row = mysql_fetch_array($query)) {
if ($prev_acc != null && $row['account'] != $prev_acc) {
$xml .= '</account>' . PHP_EOL;
}
if ($prev_app != null && $row['app_number'] != $prev_app) {
$xml .= '</apartment>' . PHP_EOL;
}
if ($prev_house != null && $row['house_number'] != $prev_house) {
$xml .= '</house>' . PHP_EOL;
}
if ($prev_street != null && $row['street'] != $prev_street) {
$xml .= '</street>' . PHP_EOL;
}
if ($row['street'] != $prev_street) {
$xml .= '<street name="' . $row['street'] . '">' . PHP_EOL;
$prev_street = $row['street'];
}
if ($row['house_number'] != $prev_house) {
$xml .= '<house number="' . $row['house_number'] . '">' . PHP_EOL;
$prev_house = $row['house_number'];
}
if ($row['app_number'] != $prev_app) {
$xml .= '<apartment number="' . $row['app_number'] . '">' . PHP_EOL;
$prev_app = $row['app_number'];
}
if ($row['account'] != $prev_acc) {
$xml .= '<account id="' . $row['account'] . '" person="">' . PHP_EOL;
$prev_acc = $row['account'];
}
$xml .= '<device id="' . $row['device_id'] . '" value="' . $row['new_meterage'] . '" date="дата" type="1"/>' . PHP_EOL;
}
$xml .= '</account>' . PHP_EOL . '</apartment>' . PHP_EOL . '</house>' . PHP_EOL . '</street>';
echo $xml;