【问题标题】:How would I be able to add an Edit to the table at the end of the table我如何能够在表格末尾向表格添加编辑
【发布时间】:2016-02-10 20:23:19
【问题描述】:

如何在表格之后向表格添加编辑。 任何帮助将不胜感激。我尝试了许多变体,例如:尝试添加编辑

      <center><?php
     //connect to mysql for search
     if(isset($_POST['search']))
     {
     $valueToSearch = $_POST['valueToSearch'];
     // search in all table columns
     // using concat mysql function
    $query = "SELECT * FROM `2016server` WHERE CONCAT(`ServerGroup`,  
    `Week`,  `Status`, `ServerName`, `IP`, `DateComplete`, `DateSched`, 
    `HeatTicket`) LIKE '%".$valueToSearch."%'";
     $search_result = filterTable($query);

     }
     else {
      $query = "SELECT * FROM `2016server`";
     $search_result = filterTable($query);
     }

     // function to connect and execute the query
      function filterTable($query)
      {
    $connect = mysqli_connect("localhost", "root", "", "");
   $filter_Result = mysqli_query($connect, $query);
    return $filter_Result;
    }

    ?>
   //start the webpage
  <html>
  <head>
    <title>SEARCH 2016 Servers</title>

   </head>
   <body>

    <center><h3>Type in your query to search all of the 2016 
    Servers</h3><br>

    <form action="search2016.php" method="post">
        <input type="text" name="valueToSearch" placeholder="SEARCH">
        <input type="submit" name="search" value="GO!"><br><br>
        table
        <table>

            <tr>
                <th>ServerGroup</th>
              <th>Server Name</th>
                  <th>Date Scheduled</th>
                 <th>Heat Ticket</th>
                <th>Status</th>
                <th>Date Complete</th>
                <th>Week</th>
                <th>Downtime</th>
                <th>IP Address</th>
                 <th>Operating System</th>


            </tr>

         populate table from mysql database 

            <?php while($row = mysqli_fetch_array($search_result)):?>
            <tr>

                <td><?php echo $row['ServerGroup'];?></td>
                <td><?php echo $row['ServerName'];?></td>
                <td><?php echo $row['DateSched'];?></td>
                <td><?php echo $row['HeatTicket'];?></td>
                <td><?php echo $row['Status'];?></td>
                <td><?php echo $row['DateComplete'];?></td>
                <td><?php echo $row['Week'];?></td>
                <td><?php echo $row['DT'];?></td>
                <td><?php echo $row['IP'];?></td>
                 <td><?php echo $row['os'];?></td>

这是我尝试在表格中添加编辑的部分。从上面的编辑代码中,它试图使用 ID 转到 2016edit.php 页面,但是由于没有这样的页面,它会收到 404 错误。

        </tr>

      <?php endwhile;?>
    </table>

  </form>

</body>
</html>

【问题讨论】:

  • 呃.......什么?你能更清楚地解释你想要做什么吗?
  • 我有一个表,我正在尝试编辑。点击编辑链接后,会进入一个php页面,你可以更新信息,然后提交给服务器。
  • 如果你想有一个额外的页面进行编辑,为什么不使用表单?
  • 我有一个表格供用户查看...我正在尝试在每一行上获取一个编辑链接,该链接将转到另一个页面进行编辑。

标签: php html search html-table edit


【解决方案1】:
  1. 提前关闭第一个&lt;form标签(在&lt;input type="submit"之后)
  2. 添加名为 action 的新列,您将在其中放置编辑按钮
  3. 用它来编辑

    <form action="youreditform.php" method="post"> <button type="submit" name="edit" value="<?= $theidofthis; ?>">Edit</button> </form>

【讨论】:

  • 我明白你想说什么。我能够在行中获得编辑,但是当我输入 $ServerName 而不是 $theIDof this 时,我得到了一个错误。
  • 我不知道$serverName 变量里面是什么以及你得到了什么错误,但它应该是你想要编辑的这一行中项目的ID。因此,如果正在提交表单,youreditform.php 将获得带有变量名的 id edit $id = filter_input(INPUT_POST, 'edit');
【解决方案2】:

添加另一个“td”标签并使其成为链接,点击后它将转到下一个编辑页面。但出于编辑目的,您必须在 url 中发布 id 以检查单击哪个记录进行编辑。希望它会有所帮助。

           <tr>
        <td><?php echo $row['ServerGroup'];?></td>
            <td><?php echo $row['ServerName'];?></td>
            <td><?php echo $row['DateSched'];?></td>
            <td><?php echo $row['HeatTicket'];?></td>
            <td><?php echo $row['Status'];?></td>
            <td><?php echo $row['DateComplete'];?></td>
            <td><?php echo $row['Week'];?></td>
            <td><?php echo $row['DT'];?></td>
            <td><?php echo $row['IP'];?></td>
            <td><?php echo $row['os'];?></td>
            <td><a href='edit.php'>edit</a></td>

        </tr>

【讨论】:

  • 不,这并不指向我需要它的特定 ID。它必须转到与其关联的行的记录。
  • 为此,您必须在 url 中发布 id 以指向特定记录。很容易
  • 我用这种技术做了同样的事情
  • 我认为我在正确的轨道上,但它不能正常工作..
  • 不,这是错误的。您的脚本将不起作用。看你只需要在重定向时在 url 中发送 id,在另一个页面上你会检查哪个 id 被发布了。如果你做不到,请告诉我。
猜你喜欢
  • 1970-01-01
  • 2012-03-16
  • 1970-01-01
  • 2016-05-07
  • 1970-01-01
  • 2019-06-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多