这让我很困惑, 我无法按顺序将表单保存到数据库中。
请看下图。
表格图像
数据库示例只保存...
所以当你看到它时,它不是 1、2、3、4,而是图像上的 1、3、2、4 我怎样才能有序地保存它?
HTML代码
<table cellpadding="5" cellspacing="0" width="100%" class="computation_table">
<tr>
<th></th>
<th>Categorieë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>
表单到数据库 $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);
});
非常感谢您的分享想法......
已编辑:更多解释...
我需要修复两件事。
首先是当它保存到我的数据库时,有序的并不是真正的跟随。
应该是 a b c d 而不是 a c b d
第二件事是我不确定我是否要使用 insertAfter() 或 insertBefore()
我的老板想要的是,他可以添加任何表单——当他点击添加按钮时,它应该添加到下面。
例如,当我单击绿色 + 添加按钮时,它应该添加到已添加的最后一个 tr 中。
我愿意解释更多......
最佳答案
尝试在点击事件中使用 append 而不是 insertAfter:
var $table = jQuery(this).closest('table')
$table.append('<tr>whatever</tr>');
关于php - foreach保存到mysqli,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17564707/
我刚刚迈出了编程的第一步。我刚刚完成了CodeAcademy的另一门类(class)。这次我被要求创建一个小电影目录。这是我的问题:如何在文件中保存/加载带有电影标题和评级的哈希值而不是自己的代码?下面是代码现在的样子(几句葡萄牙语,但您可以忽略它:movies={Memento:3,Primer:4,Ishtar:1}puts"Oquevocêgostariadefazer?"puts"--Digite'add'paraadicionarumfilme."puts"--Digite'update'paraatualizarumfilme."puts"--Digite'display'
我正在尝试将一个数组的数组保存到我在Rails中的SQLite数据库中。现在,我有一个可以容纳这样一个数组的对象,并且实例似乎可以毫无问题地保存。但是,它显然没有保存到数据库中——当我在与创建数组的View不同的View中调用My_Object.array上的函数时,结果为nil并且不起作用。例如:classMy_Object当我调用My_Object.new(:array=>[[1,2,3],[4,5,6]])时,一切似乎都正常工作,但我不能在其他任何地方访问:array属性,结果都是nil。有什么想法吗? 最佳答案 首先在您的表
我有一个带有利润字段的用户模型。利润字段是DECIMAL(11,0)类型。我在表单上有一个屏蔽输入,允许用户输入1,000美元之类的内容。我想格式化该值并从中删除除数字以外的所有内容,这样我将保存1000。这是我到目前为止所拥有的:classUser但它一直在数据库中保存0。看起来它在我的格式化函数之前将其转换为十进制。 最佳答案 试试这个:defprofit=(new_profit)self[:profit]=new_profit.gsub(/[^0-9]/,'')end 关于ruby
基本上我想要做的是在MyModelLog表中记录对MyModel的操作。这是一些伪代码:classMyModel我也有一个看起来像这样的模型:classMyModelLog"somethinghappened")endend为了记录我尝试:在MyModel的something方法中添加MyModelLog.log_something在MyModel的after_validation回调上调用MyModelLog.log_something在这两种情况下,创建都会在验证失败时回滚,因为它在验证事务中。当然我也想在验证失败时记录。我真的不想登录文件或数据库以外的其他地方,因为我需要日志条目
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭9年前。我来自C、php和bash背景,很容易学习,因为它们都有相同的C结构,我可以将其与我已经知道的联系起来。然后2年前我学了Python并且学得很好,Python对我来说比Ruby更容易学。然后从去年开始,我一直在尝试学习Ruby,然后是Rails,我承认,直到现在我还是学不会,讽刺的是那些打着简单易学的烙印,但是对于我这样一个老练的程序员来说,我只是无法将它
在RubyonRails中,如果数组为空,则具有序列化数组字段的模型将不会在.save()上更新,而它之前有数据。我正在使用:ruby2.2.1rails4.2.1sqlite31.3.10我创建了一个字段设置为文本的新模型:railsgmodel用户名:stringexample:text在我添加的User.rb文件中:serialize:example,Array我实例化了User类的一个新实例:test=User.new然后我保存用户以确保它正确保存:test.save()(0.1ms)begintransactionSQL(0.4ms)INSERTINTO"users"("cr
我正在尝试在Rails中创建一个产品页面。这包括添加多个图像。我有一种产品模型,一种用于照片,一种用于用户。我正在使用回形针gem上传照片。但是我有两个问题。我的文件输入不允许我选择多张图片当我查看产品时没有图片显示,因为图片没有保存到数据库附言我使用HAML,但我没有照片Controller。产品控制classProductsController"Salecreated!"elserender"new",:notice=>"Somehtingwentwrong!"endenddefshow@product=Product.find(params[:id])end创建产品页面=form
使用下面的ftp_download方法是可行的,但是如果我改变ftp.getbinaryfile(file,localdir,1024)#=>Savesthefiletolocaldir到ftp.getbinaryfile(file)#=>returnsnil我得到nil返回。根据http://www.ruby-doc.org/stdlib-2.0/libdoc/net/ftp/rdoc/Net/FTP.html#method-i-getbinaryfileini如果我如上所述将localfile设置为nil,该方法应该检索并返回数据。我做错了什么?defftp_download(do
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭10年前。我使用PHP的时间太长了,对它感到厌倦了。我也想学习一门新语言。我一直在使用Ruby并且喜欢它。我必须在Rails和Sinatra之间做出选择,那么您会推荐哪一个?Sinatra真的不能用来构建复杂的应用程序,它只能用于简单的应用程序吗?
我很确定Ruby有这些(等同于__call、__get和__set),否则find_by将如何在Rails中工作?也许有人可以举一个简单的例子来说明如何定义与find_by相同的方法?谢谢 最佳答案 简而言之你可以映射__调用带有参数的method_missing调用__设置为方法名称以'='结尾的method_missing调用__获取不带任何参数的method_missing调用__调用PHPclassMethodTest{publicfunction__call($name,$arguments){echo"Callingob