2013-05-31 27 views
0

我遇到了弹出式窗体的问题,该窗体中有一个字段,用户需要输入有关一行数据的某些信息。PHP:在源代码中显示echo的ID,但显示所有行的链接中的第一个ID

他/她输入的东西需要插入到表中,我会做一个更新查询...但我的问题是,形式回声的源代码中的数据库的ID,但它不显示当我将鼠标悬停在按钮上时。

我按下按钮后,它只执行第一个id的查询。其他人只显示第二个等等,直到他们逐个被删除。我不知道我在做什么错:

<?php include_once('classes/profile.class.php');?> 
<?php include_once('header.php');?> 

<h1> 

    <?php _e('Traffic Fines Adjudication'); ?> 

</h1> 

<br> 

<div class="tabs-left"> 
    <?php 

    $result = "SELECT * FROM login_fines_adjudicated WHERE active = 0 ORDER BY date_issued"; 
    $stmt = $generic->query($result); 

//this function will take the above query and create an array 
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) 
    { 
     //do nothing 
//with the array created above, I can create variables (left) with the outputted array (right) 
    $id = $row['id']; 
    $date = $row['date_added_db']; 
    $date_issued = $row['date_issued']; 
    $time_arrive = $row['time_arrived']; 
    $time_depart = $row['time_departed']; 
    $ref = $row['reference_code']; 
    $reason = $row['violation_reason']; 
    $location = $row['location']; 
    $bay = $row['bay_number']; 
    $licence = $row['licence']; 
    $punit = $row['parking_unit']; 
    $value = $row['value']; 
    $operator = $row['operator']; 
    $operator_id = $row['operator_id']; 


    //If date field is empty display nothing! Or sentence... 

    if(!empty($date)) 
    { 
?> 

    <table class="table"> 
     <thead> 
     <tr> 
      <th>Photo</th> 
      <th>Date Added</th> 
      <th>Date Issued</th> 
      <th>Time Arrived</th> 
      <th>Time Departed</th> 
      <th>Reference Code</th> 
      <th>Violation Category</th> 
      <th>Location</th> 
      <th>Bay Number</th> 
      <th>Licence Plate</th> 
      <th>Parking Unit</th> 
      <th>Amount</th> 
      <th>Operator Name</th> 
      <th>Operator ID</th> 
      <th>Action</th> 
     </tr> 
     </thead> 
     <tr> 
      <td><img class="photo" src="photos/no-available.jpg" /></td> 
      <td><?php echo $date; ?><br /></td> 
      <td><?php echo $date_issued; ?></td> 
      <td><?php echo $time_arrive; ?></td> 
      <td><?php echo $time_depart; ?></td> 
      <td><?php echo $ref; ?></td> 
      <td><?php echo $reason; ?></td> 
      <td><?php echo $location; ?></td> 
      <td><?php echo $bay; ?></td> 
      <td><?php echo $licence; ?></td> 
      <td><?php echo $punit; ?></td> 
      <td><?php echo $value; ?></td> 
      <td><?php echo $operator; ?></td> 
      <td><?php echo $operator_id; ?></td> 
      <td> 
      <form action="approve.php" method="post"> 
      <input type="hidden" name="delete_id" value="<?php echo $row['id']; ?>" /> 
      <p><a href='approve.php?id=<?php echo $id; ?>'><button url="#" class="btn btn-primary">Approve</button></a></p> 
      </form> 
        <div id="reject-form" class="modal hide fade"> 
         <div class="modal-header"> 
          <a class="close" data-dismiss="modal">&times;</a> 
          <h3><?php _e('Reject Reason'); ?></h3> 
         </div> 
         <div class="modal-body"> 
          <div id="message"></div> 
        <form action="reject.php" method="post" name="rejectform" id="rejectform" class="form-stacked rejectform normal-label"> 
         <div class="controlgroup rejectcenter"> 
           <div class="control"> 
            <input id="reject" name="reject" type="text"/> 
           </div> 
         </div> 
        <input type="hidden" name="delete_id" value="<?php echo $id; ?>" /> 
        </form> 
       </div> 
       <div class="modal-footer"> 
        <a href='reject.php?id=<?php echo $id; ?>'><button data-complete-text="<?php _e('Done'); ?>" class="btn btn-primary pull-right" id="rejectsubmit"><?php _e('Submit'); ?></button></a> 
        <p class="pull-left"><?php _e('Please give a short reason for rejecting.'); ?></p> 
        </div> 
       </div> 
       </form> 
      <p><a data-toggle="modal" href="#reject-form" id="rejectlink" tabindex=-1><button url="#" class="btn btn-primary">Reject</button></a></p> 
      </td> 
     </tr> 
    </table> 


<?php 
} 
} 
?> 
</div> 

<?php include ('footer.php'); ?> 

任何帮助,将不胜感激!

+0

什么是“日期“数据库中的字段用于?它可以是空的吗?这将是也很有帮助(虽然-I知道 - 并不总是可能的),以提供样本页面,所以我们可以看到我们自己,因为(至少对我来说)这不是很清楚的问题是什么。 – gkalpak

+0

我在这里上传https://msbodetti.com/adjudication登录:运营商,密码:1007aa。如果你登录,它会带你到我遇到问题的页面。如果您将鼠标悬停在“批准”按钮上,它会向您显示id = 1或id = 2,以及来自服务器的一个。但弹出的拒绝表单仅显示id = 1,如果您在浏览器中查看源代码,则会显示第一个id = 1,第二个id = 2。所以我很困惑! – designtocode

回答

0

问题是,您有许多具有相同id属性的元素。 Genarally,这是一个非常不好的做法,比元素更加具有相同id,更何况它不符合HTML Spec,根据该“ID = [...]此名称必须是一个文档中是唯一“。因此,强烈建议您修复所有ID,确保它是唯一的(例如,附加当前条目的ID)。

是什么原因导致你在你的问题中描述的具体问题是这样的:

  1. 您定义每个表中的弹出式对话框(div),id为reject-form
  2. 然后,您执行“拒绝”按钮作为与href="#reject-form"的链接。
  3. 所以,当你点击任何“拒绝”按钮上,用户被引导到DOM发现id="reject-form"的第一个元素(这始终是第一个条目的对话框)。

为了解决这个问题,可以追加每个条目的ID在两个位置id属性:在弹出的对话框和“拒绝”按钮上:

// Replace that: 
<div id="reject-form" class="modal hide fade"> 
// with this: 
<div id="reject-form-<?php echo $id; ?>" class="modal hide fade"> 

// Replace that: 
<a data-toggle="modal" href="#reject-form" id="rejectlink" tabindex=-1> 
// with this: 
<a data-toggle="modal" href="#reject-form-<?php echo $id; ?>" id="rejectlink" tabindex=-1> 
+0

我总是想念这些小事......对此抱歉。没意思要浪费你的时间。它正在工作:))谢谢! – designtocode

+0

NP :)总是乐于帮助! – gkalpak

相关问题