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

时间:2012-05-23 14:23:53

标签: php mysql xml insert

我需要帮助在我的数据库(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中读取

1 个答案:

答案 0 :(得分:0)

您可以尝试serialize您的数据并将其保存到任何地方,或将其保存在键值表中,并为每个“动态”表格提供唯一ID。