开发者

Is there a common method for implementing a "batch table" in PHP? [closed]

开发者 https://www.devze.com 2023-01-13 17:30 出处:网络
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this
Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 5 years ago.

Improve this question 开发者_如何转开发

Let's say I'm writing some forum software. Let's additionally say that that forum software has a personal messaging component. I'd like the user to be able to check a few messages out of that list, and then click a delete button somewhere else to delete all of those messages.

Another similar application is GMail, or pretty much every other kind of webmail application.

Is there a common pattern for implementing this? I can just stick a database row ID in each table row, but that seems like a kludge....


Actually, sticking a database-friendly identifier in every row is the standard solution to this problem. In your case, the identifier would be in the value attribute of the checkbox.

The extended pattern is to let every single operation accept a list of identifiers instead of only one (so that all your operations can act as batches).


The usuabl way of acconplishing this is to let the BROWSER send all selected IDs with an array.. similar to this:

<input name="test[]" value="123" /> foo<br />
<input name="test[]" value="133" /> bar<br />
<input name="test[]" value="3" /> barfoo<br />
<input name="test[]" value="4" /> foobar<br />

<?php
if (!empty($_GET['test']) && is_array($_GET['test'])) {
    foreach ($_GET['test'] as $k => $v) {
        echo '<br />delete id' . (int) $v;
    }
}
?>

Please note that I did not run this code. So there might be a typo in it. :D

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号