2012-08-29 30 views
0

我从我的控制器传回的数据中生成这个表,我遇到的问题是通常返回的第一条记录[在这种情况下是Sephen C. Cox],“添加员工”按钮不是重定向我,而是其余的记录工作。有谁知道这个问题?PHP窗体输出

enter image description here

<fieldset id= "results">     
<?php if (isset($results) And count($results)) : ?> 
<table id="box-table-a" summary="Employee Sheet"> 
     <thead> 
      <tr> 
       <th scope="col">Employee</th> 
       <th scope="col">Salary</th> 
       <th scope="col">Bonus</th> 
       <th scope="col">Supervisor</th> 
       <th scope="col">Action</th> 
       </tr> 


    <?php foreach ($results as $result) : ?> 
    <tr> 
    //Primary key <?php echo $result['Employee_ID!'];?> 
    <td><span class="Employee_name"><?php echo $result['Employee']; ?> </span></td>   
    <td><span class="Salary"><?php echo $result['Salary']; ?> </span> </td> 
    <td><span class="Bonus"><?php echo $result['Bonus']; ?> </span> </td> 
    <td><span class="Supervisor_name"><?php echo $result['Supervisor']; ?> </span></td> 
    <form action="welcome.php" method="post"> <td><input type="submit" value="Add employee" name="submit[<?php echo $result['Employee_ID'] ?>]" > </td></form> 
    </tr> 

     <?php endforeach; ?> 
     <?php endif; ?> 
     </thead> 
     <tbody> 
     </fieldset> 
+1

您是否尝试了不同的浏览器?我猜这可能是由您的提交按钮名称属性造成的。我只需要将名称和值作为名称来切换。编辑;还要为非法值字符转义值。 – Daniel

+0

你在'​​'之外创建一个窗体很奇怪。另外,在设置表单时,最好通过隐藏的输入类型传递员工ID。 – Raptor

+0

你能给我一个例子,我将如何通过然后在我的控制器中调用它? – Undermine2k

回答

2
<form action="welcome.php" method="post"> 
    <td> 
    <input type="submit" value="Add employee" 
    name="submit[<?php echo $result['Employee_ID'] ?>]" > 
</td></form> 

变化

<td> 
<form action="welcome.php" method="post"> 
    <input type="submit" value="Add employee" 
    name="submit[<?php echo $result['Employee_ID'] ?>]" > 
    </form> 

甚至包裹住整个表变成一种形式,而不是把新的形式进入各行的。看到你的代码没有任何理由,可能需要

编辑: 此外,看一看像萤火虫(FF),检查在Chrome和Safary,开发工具,或者它是如何被调用的工具,在IE浏览器。用这些工具之一打开你的页面已经足够了,并且注意到浏览器不像你期望的那样分析你的代码。