2014-08-22 17:27


  • 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;


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

            $return.="<tr class='$thisClass'>
                            <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>

    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?

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