drcmg28484 2015-11-08 16:34
浏览 39

echo复选框,选中时将完成设置为数据库中的ID

I have a table that I am echoing out and now I added a check box to the end of it.

I would like when that box is checked. It can be checked on multiple items and then the save button is clicked. It would go to the post page and set complete in the database to "Yes" for all the IDs that were checked.

Problem is I do not understand how the checkbox will know which ID is which once it goes to the post page.

<?php

$conduct = $_SESSION['username'];
$query = mysqli_query($con, "SELECT * FROM newworders WHERE train = 'Yes' AND conductor = '$conduct' AND complete = ' '");

echo "<table id='tb' border='1'>
          <tr class='head'>
              <th>First Name</th>
              <th>Last Name</th>
          </tr>";

while($row = mysqli_fetch_array($query)) {
    echo "<tr>";
    echo "<td>" . '<a href="orderpage.php?uid=' . $row['ID'] . '">' . $row['first'] . '</a><br />' . "</td>";       
    echo "<td>" . '<a href="orderpage.php?uid=' . $row['ID'] . '">' . $row['last'] . '</a><br />' . "</td>";
    echo "<td>"."<input type='checkbox' value='Yes' name='complete'" . "</br>". "</td>";
}

<div class='new'>
    <form action="savepending.php" method='POST'>
        <input type='submit' name ='save'/>     
    </form>
</div>

Then the post page.

<?php
  if(isset($_POST['save']))
  { 
    $query = mysqli_query($con, "UPDATE newworders SET complete = 'Yes'  WHERE ")
  }
?>

I have no idea what to put in the WHERE part. I just dont understand how it will tell which ID is which.

  • 写回答

1条回答 默认 最新

  • douqu2481 2015-11-08 18:16
    关注

    Make your checkboxes an arrray, indexed by newworders primary key. Then you can just iterate through complete. PHP arrays are associative, so you will only have as many elements as you have checkboxes.

    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效