如何从表行中获取值?

时间:2016-10-01 17:02:18

标签: php html

这是表格形式,我将使用按钮编辑

选择要编辑的行
$query = "SELECT * FROM tbl_document LIMIT $start, $end";
$result = mysqli_query($con,$query);
echo "<table border='1' width='300' height='160' align = center id='result'>";
echo '<tr>
     <th width="80">ID</th>
     <th width="200">Title</th>
     <th width="260">Presented To</th>
     <th width="260">Presented By</th>
     <th width="160">Date Submitted</th>
     <th>Location</th>
     <th width="17%">Option</th>
</tr>';
while($row = mysqli_fetch_array($result)){
    echo "<tr align = center >";
    echo "<td width='20' height='60'>" .$row['ID']. "</td>";
    echo "<td width='120' height='60'>" .$row['Title']. "</td>";
    echo "<td>" .$row['Presented_To']. "</td>";
    echo "<td>" .$row['Presented_By']. "</td>";
    echo "<td>" .$row['Date_Submitted']. "</td>";
    echo "<td>" .$row['Location']. "</td>";
    echo "<td width='17%'>";
?>
<p>
    <button onclick="document.getElementById('edtID').style.display='block'" value="<?php echo $row['ID']; ?>" class="w3-btn w3-blue w3-border-large w3-circle" id="edit" name="edit" style="width:60%"><i class="fa fa-edit"></i>&nbsp;Edit</button>

这是第二个代码,这个表单是模态的,我点击表格中的按钮和模态显示你可以编辑但我的代码缺少什么?

<form method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<p>
<label class="w3-label w3-text-black"><strong>Title:</strong></label>
<input class="w3-input w3-hover-light-blue w3-animate-input w3-border-large w3-light-grey" style="width:100%" type="text" id="title" name="title" placeholder="Title" value=<?php $row['Title']; ?>required></span>
</p>
</form>

1 个答案:

答案 0 :(得分:0)

在你的第二张表格(你的模态)上,我看不到回音显示标题的值

<form method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<p>
<label class="w3-label w3-text-black"><strong>Title:</strong></label>
<input class="w3-input w3-hover-light-blue w3-animate-input w3-border-large w3-light-grey" style="width:100%" type="text" id="title" name="title" placeholder="Title" value=<?php echo $row['Title']; ?>required></span>
</p>
</form>

此外,对于您的第一个表单,您可以这样写

<table border='1' width='300' height='160' align=center id='result'>
  <tr>
     <th width="80">ID</th>
      <th width="200">Title</th>
      ...
  </tr>

  <?php

  while($row = mysqli_fetch_array($result))
  {
       echo "<tr align = center >";
       echo "<td width='20' height='60'>" .$row['ID']. "</td>";
       echo "<td width='120' height='60'>" .$row['Title']. "</td>";
       ...
  ?>

  <p>
      <button onclick="document.getElementById('edtID').style.display='block'" value="<?php echo $row['ID']; ?>" class="w3-btn w3-blue w3-border-large w3-circle" id="edit" name="edit" style="width:60%">
        <i class="fa fa-edit"></i>&nbsp;Edit
      </button>
   </p>

  <?php

  }

  ?>

最后,您应该开始将PDO用于与数据库相关的所有内容。