dongmanni6916
dongmanni6916
2014-08-22 17:27

在具有变量ID的php中捕获POST数据

  • php

I'm creating a form from a database and the input id's could be 1-9, 1,2,5,8, etc. IE with the way it is now, I cannot determine what the number will be unless I were to iterate from number 1 to the final number of menu items in the database... which I imagine is not optimal from a coding perspective.

I have two files. File1 will get list number of menu items from a database and create a list. The condensed version of my code is as follows, please keep in mind i have condensed a lot of useless stuff;

File1.php

    $menuArray = openMenu(1);
    $return = "<div id='menu'><form method='post' action='file2.php'><input type='submit' name='submit' value='Commit Order' /><table class='tableinfo'>";
    $i=1;
    foreach($menuArray as $recordNum => $record)
    {
            if ($record['available'] > 0)
            {
                    $thisClass='available';
            } else{
                    $thisClass='unavailable';
            }

            $return.="<tr class='$thisClass'>
                            <td>$record[itemid]</td>
                            <td><label for='$record[itemid]'>$record[name]</label></td>
                            <td><button type='button' id='itemid-$record[itemid]' class='subtract'>-</button><input class='itemadder' id='itemid-$record[itemid]' type='number' min='0' value='0' /><button id='itemid-$record[itemid]' class='addition' type='button'>+</button></td>
                    </tr>";
    }
    $return.="</table></form></div>";

    return $return;

File2.php I don't know how to code this :(

Is anyone able to shed some light on the best way to do this? I just need a way to be able to see what id's have a value when posted.

I am using jQuery at the moment; would this be something best done using jquery?

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐

换一换