dongyou6768 2015-01-28 12:05
浏览 44
已采纳

使用PHP从HTML中检索变量变量

I am creating a HTML page that creates a large excel database, and gives the user the option to search and display the contents filtering certain parameters. This works great so far, however now I am trying to add the option to update the excel database based on user input from the user changing the generated textboxes in the HTML page. When my php generates the textboxes I had it generate the name of the textbox as the name of the cell it pulled the data from. Now when trying to pull the changed data from the html text box, I would like to use $_GET[$cell], cell being the variable in php which runs in a loop to generate the names of each cell or corresponding labeled html textbox. I know this cannot be done this way, which is why I am looking for an alternative. Any ideas? -Thank you

<html>
<head>
<meta http-equiv="Content-Type" content="text/html"; charset=ISO-8859-1">
                                                                        
                                                                    
   <button type ="submit" name="Submit" value="Revise" onclick="f1.action='Revise.php';return true;"> Revise </button>
                                                                                                    
                                                                                                    
<iframe width="4000" height="2000000" name="myiframe" src="Revise.php" method = "get"


    
    
        <tr>
    <td> <input type ='text' value= 'DLWR' name'C3'/></td><td> <input type ='text' value= 'DLWR' name'D3'/></td><td> <input type ='text' value= '2003' name'E3'/></td><td> <input type ='text' value= 'NS  ' name'F3'/></td><td> <input type ='text' value= 'NS  ' name'G3'/></td><td> <input type ='text' value= 'MTH' name'H3'/></td><td> <input type ='text' value= 'S ' name'I3'/></td><td> <input type ='text' value= '0' name'N3'/></td><td> <input type ='text' value= 'NS  ' name'O3'/></td><td> <input type ='text' value= '185400' name'P3'/></td><td> <input type ='text' value= 'E' name'R3'/></td><td> <input type ='text' value= 'LCS' name'S3'/></td><td> <input type ='text' value= 'O ' name'T3'/></td><td> <input type ='text' value= '52' name'Y3'/></td><td> <input type ='text' value= '187366' name'AA3'/></td><td> <input type ='text' value= '52' name'AC3'/></td><td> <input type ='text' value= '0' name'AD3'/></td><td> <input type ='text' value= '0.41' name'AE3'/></td><td> <input type ='text' value= '0' name'AG3'/></td><td> <input type ='text' value= '21.32' name'AH3'/></td><td> <input type ='text' value= '21.32' name'AK3'/></td><td> <input type ='text' value= '20140528' name'AO3'/></td><td> <input type ='text' value= '198097' name'AP3'/></td><td> <input type ='text' value= 'NS  ' name'AQ3'/></td><td> <input type ='text' value= 'E' name'AR3'/></td><td> <input type ='text' value= '4029176' name'AS3'/></td><td> <input type ='text' value= 'DLWR' name'C4'/></td><td> <input type ='text' value= 'DLWR' name'D4'/></td><td> <input type ='text' value= '2003' name'E4'/></td><td> <input type ='text' value= 'OHRY' name'F4'/></td><td> <input type ='text' value= 'OHRY' name'G4'/></td><td> <input type ='text' value= 'LCS' name'H4'/></td><td> <input type ='text' value= 'O ' name'I4'/></td><td> <input type ='text' value= '52' name'N4'/></td><td> <input type ='text' value= 'NS  ' name'O4'/></td><td> <input type ='text' value= '187366' name'P4'/></td><td> <input type ='text' value= 'E' name'R4'/></td><td> <input type ='text' value= 'LCB' name'S4'/></td><td> <input type ='text' value= 'S ' name'T4'/></td><td> <input type ='text' value= '63' name'Y4'/></td><td> <input type ='text' value= '187366' name'AA4'/></td><td> <input type ='text' value= '11' name'AC4'/></td><td> <input type ='text' value= '0' name'AD4'/></td><td> <input type ='text' value= '0.41' name'AE4'/></td><td> <input type ='text' value= '0' name'AG4'/></td><td> <input type ='text' value= '4.51' name'AH4'/></td><td> <input type ='text' value= '4.51' name'AK4'/></td><td> <input type ='text' value= '20140528' name'AO4'/></td><td> <input type ='text' value= '198097' name'AP4'/></td><td> <input type ='text' value= 'NS  ' name'AQ4'/></td><td> <input type ='text' value= 'E' name'AR4'/></td><td> <input type ='text' value= '4029176' name'AS4'/></td><td> <input type ='text' value= 'DLWR' name'C5'/></td><td> <input type ='text' value= 'DLWR' name'D5'/></td><td> <input type ='text' value= '2003' name'E5'/></td><td> <input type ='text' value= 'OHRY' name'F5'/></td><td> <input type ='text' value= 'OHRY' name'G5'/></td><td> <input type ='text' value= 'LCB' name'H5'/></td><td> <input type ='text' value= 'S ' name'I5'/></td><td> <input type ='text' value= '63' name'N5'/></td><td> <input type ='text' value= 'OHRY' name'O5'/></td><td> <input type ='text' value= '187366' name'P5'/></td><td> <input type ='text' value= 'L' name'R5'/></td><td> <input type ='text' value= 'LCS' name'S5'/></td><td> <input type ='text' value= 'P ' name'T5'/></td><td> <input type ='text' value= '63' name'Y5'/></td><td> <input type ='text' value= '187366' name'AA5'/></td><td> <input type ='text' value= '0' name'AC5'/></td><td> <input type ='text' value= '0' name'AD5'/></td><td> <input type ='text' value= '0.41' name'AE5'/></td><td> <input type ='text' value= '0' name'AG5'/></td><td> <input type ='text' value= '0' name'AH5'/></td><td> <input type ='text' value= '0' name'AK5'/></td><td> <input type ='text' value= '20140603' name'AO5'/></td><td> <input type ='text' value= '306552' name'AP5'/></td><td> <input type ='text' value= 'NS  ' name'AQ5'/></td><td> <input type ='text' value= 'L' name'AR5'/></td><td> <input type ='text' value= '4021125' name'AS5'/>
    <br />
    </iframe>
        
    
</body>
</html>

And the PHP portion that calls each textbox individually would look like this in a perfect world:

 for($n=1; $n<27; $n++){
  $cell = $x . $y; 

   if(isset($_GET[$cell])){
   $string = $_GET[$cell];
    }
    else{ 
    break 1;
    }
 $objWorksheet ->getCell($cell) ->setValue($string);

  echo "<td> <input type ='text' value= '$string' name = '$cell'/></td>";

  $x=++$x;
  }
</div>
  • 写回答

1条回答 默认 最新

  • dongtiao2105 2015-01-28 12:13
    关注

    try it first with a normal form mechanism in html and as backend php, afterwards you can change it without any big changes to use ajax or so.

    <form method="POST" action="backend.php" id="excelform">
       <input type="text" value="foo" name="D3" /> 
       <button type="submit">Submit</button>
    </form>
    

    your backend.php could look like:

    <?php
    $cell = "D3";
    
    var_dump($_POST[$cell]);
    die();
    

    after you get this working you can send your data via an AJAX call (with jQuery) do:

    $("#excelform").submit(function( event ) {
    
      var form = $("#excelform");
      $.post(form.attr("action"), form.serialize()).done(function( data ) {
         alert( "Data Loaded: " + data );
      });
    
      //prevent the form to really send to another page
      event.preventDefault();
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么