duan205571 2015-03-05 23:44
浏览 35

从动态html表上的删除更新按钮获取值。 php mysql

i am developing a webpage with a table that's populated dynamically when the page is loaded. i have a delete/update buttons on each row of the table, but i cant figure out how to get the value (message id) of the selected table row so i can run the delete/edit script on the correct record.

this is the code that populates the table:

while ($row=mysqli_fetch_array($run_post)){
       $post_date=$row['msg_post_date'];
       $post_title=$row['msg_title'];
       $post_id=$row['msg_id'];
       $post_list[]=$row['msg_id'];

       //table post date
       echo "<td><div class='thumbnail-mar-less'>$post_date</div></td>";

       //table title
       echo "<td><div class='thumbnail-mar-less'><a href='#'>$post_title</a></div></td>";

       //table buttons
       echo "<td>
       <form class='form-inline thumbnail-mar-less' role='form'>
         <div class='form-group'><button class='btn btn-default btn-sm'>Edit Post</button></div>
         <div class='form-group'><button name='delete'value=' ' class='btn btn-primary btn-sm'>Delete</button></div>
         </div>
        </td>";
        echo "</tr>";
} 

any suggestions on how i would assign and retrieve a value to each row???

  • 写回答

1条回答 默认 最新

  • dtf1111 2015-03-06 00:43
    关注

    You form has no "action", so it will submit to the "current" url automatically. If the current url is the same page as your form handling PHP then that's okay. Your form has no closing tag, so, the rest may look strange on the page.

    as bobdye and Simon MᶜKenzie pointed out, you should have a field in the form that contains the $post_id value.

    try something like this:

    echo '
            <form class="some fancy classes" action="some_handler.php">
                <input type="hidden" value="'.$post_id.'">
                <input type="submit" value="go!">
            </form>
         ';
    
    评论

报告相同问题?

悬赏问题

  • ¥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之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改