0

我需要帮助在我的数据库(mysql)中插入一个表。该表是通过读取 .xml 文件创建的,行数取决于 .xml 文件具有的营地数,下面的代码对应于我打印结果的方式。

几个人问我代码我在这里使用读取.xml,我希望能帮助我弄清楚如何进行插入

 <?php require_once('Connections/conection_siipo.php'); ?>
  <?php

  $data = array();

  function add_person( $operation, $description, $zone, $workshop )
  {
  global $data;

  $data []= array(
  'operation' => $operation,
  'description' => $description,
  'zone' => $zone,
  'workshop' => $workshop 
  );
  }

  if ( $_FILES['file']['tmp_name'] )
  {
  $dom = DOMDocument::load( $_FILES['file']['tmp_name'] );
  $rows = $dom->getElementsByTagName( 'Row' );
  $first_row = true;
  foreach ($rows as $row)
  {
  if ( !$first_row )
  {
  $operation = "";
  $description = "";
  $zone = "";
  $workshop = "";

  $index = 1;
  $cells = $row->getElementsByTagName( 'Cell' );
  foreach( $cells as $cell )
  { 
  $ind = $cell->getAttribute( 'ss:Index' );
  if ( $ind != null ) $index = $ind;

  if ( $index == 1 ) $operation = $cell->nodeValue;
  if ( $index == 2 ) $description = $cell->nodeValue;
  if ( $index == 3 ) $zone = $cell->nodeValue;
  if ( $index == 4 ) $workshop = $cell->nodeValue;

  $index += 1;
  }
  add_person( $operation, $description, $zone, $workshop );
  }
  $first_row = false;
      }
      }

?>

HTML

<table>
    <tr>
        <th>Operation</th>
        <th>Description</th>
        <th>Zone</th>
        <th>Workshop</th>
    </tr>

    <?php foreach( $data as $row ) { ?>
    <tr>
        <td><?php echo( $row['operation'] ); ?></td>
        <td><?php echo( $row['description'] ); ?></td>
        <td><?php echo( $row['zone'] ); ?></td>
        <td><?php echo( $row['workshop'] ); ?></td>
    </tr>
    <?php } ?>
</table>

这段代码是数据的结果,所以我需要帮助来在我的数据库中构建一个插入:

<table>
  <tr>
     <th>Operation</th>
     <th>Description</th>
     <th>Zone</th>
     <th>Workshop</th>
  </tr>
  <tr>
     <td>LAN_CQM_CHK_T001BE1N_2</td>
     <td>200002-01-1-REINS(JIC) (GENERAL VISUAL INSPECTION OF ELEMENTS FITTED ON THE FOLLOWING HARNESSES: 400VB, 401VB, 402VB, 403VB, 404VB, 405VB, 406VB, 407VB, 408VB, 409VB)</td>
     <td>300</td>
     <td>40</td>
  </tr>
  <tr>
     <td>LAN_CQM_CHK_T001BE1M_3</td>
     <td>200002-01-1-REM(JIC) (GENERAL VISUAL INSPECTION OF ELEMENTS FITTED ON THE FOLLOWING HARNESSES: 400VB, 401VB, 402VB, 403VB, 404VB, 405VB, 406VB, 407VB, 408VB, 409VB)</td>
     <td>300</td>
     <td>40</td>
  </tr>
  <tr>
     <td>LAN_CQM_CHK_T001BK4W_4</td>
     <td>200315-01-1-INSP(JIC) (GENERAL VISUAL INSPECTION OF G AND P ROUTE WIRING INSTALLED IN THE TAIL CONE AND APU ACCESSORY COMPARTMENT)</td>
     <td>300</td>
     <td>34</td>
  </tr>
  <tr>
     <td>LAN_CQM_CHK_T001BK56_5</td>
     <td>200413-01-1-ENG2-INSP(JIC) (DETAILED INSPECTION OF ALL WIRING INSTALLED IN THE UPPER FORWARD PYLON)</td>
     <td>400</td>
     <td>34</td>
  </tr>
  <tr>
     <td>LAN_CQM_CHK_T001FX2Z_6</td>
     <td>200413-03-1-ENG1-INSP(JIC) (DETAILED INSPECTION OF EWIS INSTALLED IN THE UPPER FORWARD PYLON (EWIS))</td>
     <td>400</td>
     <td>40</td>
  </tr>
  <tr>
     <td>chong</td>
     <td>200413-03-1-ENG2-INSP(JIC) (DETAILED INSPECTION OF EWIS INSTALLED IN THE UPPER FORWARD PYLON (EWIS))</td>
     <td>400</td>
     <td>40</td>
  </tr>

如何保存表格的内容,因为有时 .xml 文件有超过 100 行?

如何从动态表中插入?,从 .xml 文件 PHP 中读取

4

1 回答 1

0

您可以尝试序列化您的数据并将其保存在任何地方,或者将其保存在键值表中,每个“动态”表具有唯一的 ID。

于 2012-05-23T14:40:34.220 回答