存储生成的输入字段的排名
我陷入了一些我自己无法解决的问题:(不幸的是......我需要在我的表中存储 jQuery 生成的一些输入字段的排名,让我解释一下:
当我单击按钮时,我添加一个输入字段在我的页面中,生成的每个输入字段都有一个递增的名称(name0,name1 ...)和一个递增的id(item-1,item-2等)
我使用jQuery的可排序功能,一切都很好,我拖动放弃我的田地,他们有 我序列
化所有内容,它给了我: item[]=0&item;[]=2&item;[]=1&item;[]=3 每个字段都有一个排名。我的数据库中的这个排名与关联的字段(我的表看起来像这样:“id”“排名”“id”字段自动递增)
这是我的代码:
添加字段的 JS 函数:
$(function() {
var item = 'item-';
var i = 0;
var k = 0;
var deletebtn = "<div id='deletebtn'>delete this</div>";
$("#button_add").live("click", function(){
$('#reorder').append("<li id="+ item + i++ +" class='list_item'>" + "<input type='text' name='title"+ k++ +"' value='' kind='title' />" + deletebtn + "</li>");
});
});
TO获取序列化结果:
newRank = $("#reorder").sortable("serialize");
$("#rank").val(newRank);
这链接到一个输入字段以获取序列化值
<input type="hidden" id="rank" name="rank" value="" />
PHP TO $_POST 输入字段:
$rank = $this->input->post('rank');
// THIS WILL GIVE ME THE RESULT : item[]=0&item;[]=2&item;[]=1&item;[]=3
是否有想法将与其 id 相对应的每个字段的排名存储在我的数据库中? !!
I’m stuck on something that I can’t fix by myself :( Unfortunately… I need to store a rank from some inputs fields generated by jQuery in my TABLE, let me explain :
When I click on a button I add an input field in my page, each input field generated have an incremented name (name0, name1 ...) and an incremented id (item-1, item-2 and so on)
I use the sortable function of jQuery and everything is okay, I drag and drop my fields and they have their order.
I serialize everything and it gives me that : item[]=0&item;[]=2&item;[]=1&item;[]=3 each field have a rank. Well now I need to store this rank in my DB WITH the field associated (my TABLE look like this : ‘id’ ‘rank’ the ‘id field is auto incremented)
Here’s my code :
THE JS FUNCTION TO ADD FIELDS :
$(function() {
var item = 'item-';
var i = 0;
var k = 0;
var deletebtn = "<div id='deletebtn'>delete this</div>";
$("#button_add").live("click", function(){
$('#reorder').append("<li id="+ item + i++ +" class='list_item'>" + "<input type='text' name='title"+ k++ +"' value='' kind='title' />" + deletebtn + "</li>");
});
});
TO GET THE SERIALIZE RESULT :
newRank = $("#reorder").sortable("serialize");
$("#rank").val(newRank);
This is linked to an input field to get the serialized value
<input type="hidden" id="rank" name="rank" value="" />
THE PHP TO $_POST THE INPUT FIELD :
$rank = $this->input->post('rank');
// THIS WILL GIVE ME THE RESULT : item[]=0&item;[]=2&item;[]=1&item;[]=3
Any idea to store the rank of each field corresponding to their id in my DB ? Any help would be very very appreciated !!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解正确,您当然可以从
$rank
创建一个数组并循环遍历您的数据库插入:您的 $rank 中有一些额外的分号,但不确定是否存在是不是拼写错误。
If I'm understanding you correctly, you could of course create an array from
$rank
and loop through for your db inserts:There are some extra semi-colons in your $rank, but not sure if that is a typo or not.