简体   繁体   中英

How to post all rows where table row ID's are not in sequence

I have an HTML Table in a form. each table row has a unique ID. I have jquery adding and deleting rows. you can see the fiddle http://jsfiddle.net/gUYpL/

So every time a user adds a row, the counter is added to the row so for three rows you obviously have first_name1,first_name2,first_name3

if I then delete row 2, I then have first_name1,first_name3 .

What is the best way to loop through each 'row' of post information?

so currently I use:

$i=1;
    while($i<=$maxid) {write info to database}

So 3 from first_name3... but actually only 2 rows as first_name2 deleted

Is there an option with foreach? Something like:

foreach ($lineid as $value) {
    write info to database
}

Apologies if this is an obvious question, just need some help.

Thanks in advance...

Not sure if I get this question completely but in PHP you can do:

$arr = array(1, 2, 3, 4);
foreach ($arr as $value) {
     $value = $value * 2;
}
// $arr is now array(2, 4, 6, 8)

Also you can work with array_keys and loop over that ;)

$array = array("name1" => "Ted", "name3" => "Dude");
$keys = array_keys($array);
for($i = 0; $i<sizeof($keys); $i++){
             echo $array[$keys[$i]]; //echo Ted and then Dude
}

This is not tested but I think this is correct.

您应该从行ID'first_name3'的最后一位开始获取元素位置,以便可以正确映射它,也可以将其分配给新数组(如果您只希望实际计数)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM