php – foreach保存到mysqli

这让我很困惑,
我无法将表单有序地保存到我的数据库中.

请看下面的图片.
形式图像

数据库示例仅保存…

所以当你看到它不是1,2,3,4但在图像上是1,3,2,4
我该如何有条不紊地保存?

HTML代码

<table cellpadding="5" cellspacing="0" width="100%" class="computation_table">
<tr>
    <th></th>
    <th>Categorie&euml;n</th>
    <th>Aantal</th>
    <th>Omschrijving</th>
    <th>bedrag</th>
    <th>Totaal</th>
    <th>BTW</th>
    <th></th>
</tr>
<tr>
    <td>
    <a id="add_new_element"><img src="images/add.png" width="20" alt="add product" /></a> 
    <a id="add_new_category"><img src="images/cat.png" alt="add category" /></a>
    </td>
    <td align="left" colspan="6">
        <input type="text" name="input[0][cat_name]" style="font-weight:bold;" value="Categorie naam" />
    </td>
</tr>
<tr>
    <td>
    <a id="add_new_element"><img src="images/add.png" width="20" alt="add product" /></a>
    <a id="add_new_category"><img src="images/cat.png" alt="add category" /></a>
    </td>
    <td>
        <input type="text" name="input[0][category]" class="text_com" value="" />
    </td>
    <td>
        <input type="text" name="input[0][quantity]" id="new_quan" class="quantity text_com" value="" /> x
    </td>
    <td width="180">
        <textarea name="input[0][quo_deFinition]" class="input"></textarea>
    </td>
    <td>
        <input type="text" name="input[0][quo_amt]" id="new_amt" class="quantity text_com" value="0" />
    </td>
    <td id="total">
        <span id="view_total_0">0</span>
        <input type="hidden" name="input[0][quo_total]" id="new_total" class="quantity text_com" value="0" />
    </td>
    <td>
        <select name="input[0][quo_btw]" class="btwselect">
            <option value="21%" selected="selected">21%</option>
            <option value="6%">6%</option>
            <option value="0%">0%</option>
        </select>
    </td>
</tr>
</table>
<br />
<div class="ClientProductItemsSubTotal">
<table cellpadding="5" cellspacing="0" width="100%">
<tr>
<td><strong>Korting</strong></td><td><input type="text" name="discount" class="quantity" value="" /></td>
</tr>
</table>
</div>

form to DB $input = array();

foreach( $_POST['input'] as $input ) {
$MysqLi->query( "INSERT INTO jon_com_quo_computation VALUE('', '$uc', '$cc', '$ct', '$cur', '', '".$input['cat_name']."', '".$input['category']."', '".$input['quantity']."', '".$input['quo_deFinition']."', '".$input['quo_amt']."', '".$input['quo_total']."', '".$input['quo_btw']."', '$dis', '', '', '1', 'new', Now() )" );
}

jQuery添加下面的表单…应该在底部…我使用.insertAfter(rowfield);

jQuery(function() {    
id = 0;
jQuery('a#add_new_element').live('click', function() {
id++;

var rowfield = jQuery(this).parent().parent();//add some .parent() untill you get the TR element
jQuery('<tr><td><a id="add_new_element"><img src="images/add.png" width="20" alt="add product" /></a> <a id="add_new_category"><img src="images/cat.png" alt="add category" /></a></td><td><input type="text" name="input['+id+'][category]" class="text_com" value="" /></td><td><input type="text" name="input['+id+'][quantity]" id="new_quan" class="quantity" value="" /> x</td><td width="200"><textarea name="input['+id+'][quo_deFinition]" class="input"></textarea></td><td><input type="text" name="input['+id+'][quo_amt]" id="new_amt" class="quantity" value="0" /></td><td><span id="view_total_'+id+'">0</span><input type="hidden" id="new_total" name="input['+id+'][quo_total]" class="quantity" value="0" /></td><td><select name="input['+id+'][quo_btw]" class="btwselect"><option value="21%" selected="selected">21%</option><option value="6%">6%</option><option value="0%">0%</option></select></td><td><a id="del_row"><img src="images/del.png" class="DelRow" alt="delete" /></a></td></tr>').insertAfter(rowfield);

});

非常感谢你的分享想法….

编辑:更多解释……
我需要解决两件事.
首先是当它保存到我的数据库时,有序的并不是真正遵循的.
应该是b c d而不是c b d

第二件事是我不确定我是否会使用insertAfter()或insertBefore()
我的老板想要的是,他可以添加任何形式 – 当他点击添加按钮时,它应该在下面添加.

例如,当我单击绿色添加按钮时,它应该添加到已添加的最后一个tr.

我愿意解释更多……

解决方法:

尝试在click事件中使用append而不是insertAfter:

var $table = jQuery(this).closest('table')
$table.append('<tr>whatever</tr>');

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...