Tell pzhl how to fill the Region column through a loop (foreach)

<?php $query="select f.full_name f_name,d.* from zrdt.report_detail d,zrdt.filial f where f.id=d.filial_id and report_id=".$report_id." and report_result_id=".$report_result_id." order by filial_id" ; //echo $query;exit; $database->setQuery( $query ); $rows = $database->loadObjectList(); $xml_data_begin='<?xml version="1.0"?> <?mso-application progid="Excel.Sheet"?> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40"> <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office"> <Author>Nurzhaubay AN</Author> <LastAuthor>Radmin</LastAuthor> <Created>1980-02-15T00:00:01Z</Created> <Version>12.00</Version> </DocumentProperties> <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel"> <ProtectStructure>False</ProtectStructure> <ProtectWindows>False</ProtectWindows> </ExcelWorkbook> <Worksheet ss:Name="Result">'; $xml_data_end='<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel"> <ProtectObjects>False</ProtectObjects> <ProtectScenarios>False</ProtectScenarios> </WorksheetOptions> </Worksheet> </Workbook>'; if (ob_get_level()) {ob_end_clean();} // header('Content-Description: File Transfer'); header("Content-type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename=employee.xml"); echo $xml_data_begin; //Наименование столбца(Колонка-РЕГИОН) echo '<Table x:FullColumns="1" x:FullRows="1" ss:DefaultRowHeight="15"> <Row ss:AutoFitHeight="0"> <Cell><Data ss:Type="String">'.mb_convert_encoding("Регион", "utf-8","windows-1251").'</Data></Cell> </Row> </Table>'; //Для каждого региона из запроса в БД ($query) foreach($rows as $row) { echo '<Row ss:AutoFitHeight="0">'; echo '<Cell><Data ss:Type="String">'.mb_convert_encoding(trim($row->F_NAME), "utf-8","windows-1251").'</Data></Cell>'; echo '</Row>\n'; } echo $xml_data_end; exit(); ?> 
  • And what produces $ rows if it is viewed through print_r ($ rows); ? - Chinese IzKita
  • It simply displays the word Region in cell A1. And I need him to fill the column Region - Zhandos Kazkeev
  • Your request is confusing and in my opinion not correct. ($ query = "select f.full_name f_name, d. * from) try this ($ query =" select f.full_name as F_NAME from) And here, too, is not clear (where f.id = d.filial_id) You are a branch-ID how do you get? To further use it in the request? - Chinese IzKita
  • I have a suspicion that your request to the database or incorrect or affects 0 entries. Show the output of this code chunk: try { $database->setQuery($query); $rows = $database->loadObjectList(); echo "count: " . count($rows); } catch (\RuntimeException $e) { echo $e->getMessage(); } exit; try { $database->setQuery($query); $rows = $database->loadObjectList(); echo "count: " . count($rows); } catch (\RuntimeException $e) { echo $e->getMessage(); } exit; - Jigius
  • The request is correct. There are 2 tables 1) zrdt.report_detail d 2) zrdt.filial f and where f.id = d.filial_id - Zhandos Kazkeev

1 answer 1

Thank you all very much !!!!

Found a mistake. It was even stupid of me to ask for help (((((Sorrri

Here is the code. Can someone useful.

 <?php $query="select f.full_name f_name,d.* from zrdt.report_detail d,zrdt.filial f where f.id=d.filial_id and report_id=".$report_id." and report_result_id=".$report_result_id." order by filial_id" ; //echo $query;exit; $database->setQuery( $query ); $rows = $database->loadObjectList(); $xml_data_begin='<?xml version="1.0"?> <?mso-application progid="Excel.Sheet"?> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40"> <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office"> <Author>Nurzhaubay AN</Author> <LastAuthor>Radmin</LastAuthor> <Created>1980-02-15T00:00:01Z</Created> <Version>12.00</Version> </DocumentProperties> <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel"> <ProtectStructure>False</ProtectStructure> <ProtectWindows>False</ProtectWindows> </ExcelWorkbook> <Worksheet ss:Name="Result">'; $xml_data_end='<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel"> <ProtectObjects>False</ProtectObjects> <ProtectScenarios>False</ProtectScenarios> </WorksheetOptions> </Worksheet> </Workbook>'; if (ob_get_level()) {ob_end_clean();} // header('Content-Description: File Transfer'); header("Content-type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename=employee.xml"); echo $xml_data_begin; //Наименование столбца(Колонка-РЕГИОН) echo '<Table x:FullColumns="1" x:FullRows="1" ss:DefaultRowHeight="15"> <Row ss:AutoFitHeight="0">'; echo '<Cell><Data ss:Type="String">'.mb_convert_encoding("Регион", "utf-8","windows-1251").'</Data></Cell>'; echo '</Row>'; foreach($rows as $row) { echo '<Row>'; echo '<Cell><Data ss:Type="String">'.mb_convert_encoding(trim($row->F_NAME), "utf-8","windows-1251").'</Data></Cell>'; echo '</Row>'; }; echo '</Table>'; echo $xml_data_end; exit(); ?>