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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化