doufei1988 2013-09-25 20:48
浏览 74
已采纳

将使用jquery add_function创建的多个输入数据插入到mysql中

I have the following html:

<h4>Add Steps</h4>
<ul id="pasi">
 <li>
<span>Pasul 1: </span><textarea id="pas"></textarea>
<input  id="add_pas" type="button" value="Add Step" onclick="add_pas()"/>
 </li>
<input id=""  type="button" value="Add recipe" />

and this jquery function:

    function add_pas() {
var pas = "Pasul " + i;
var list = $('#pasi');
var html = "<li class='pas-"+ pas +"'><span>" + pas + "</span><textarea></textarea><img src='../images/x.png' /></li>";

list.each(function(){
    $(this).append(html);
    });
    i++
}

The function adds a new step when the button is clicked.

SQL:

    TABLE recipe_steps (id, recipe_id,sort_oder,description)

My question is how do I insert the custom number of steps into the database, and then how to retrieve it. A first thaught was to insert all the steps into a vector(steps[]) but I don't really know where to start. Please take in consideration that I'm a begginer in php, mysql, jquery . Thank you and I hope I made it as clear as possible.

  • 写回答

2条回答 默认 最新

  • dongpao1083 2013-09-27 00:53
    关注

    I came up with this that worked

     function trimite(){
    var pasi = {};  //initializing an array
    var k=0;
    $(".nimic").each(function () {  //class of the <textarea>
        pasi[k]=$(this).val();  //takes the value for each of the textareas created
        k++;
    });
    
    
    $.ajax({ // sends all the textarea created to the php processing script
        type:'POST',
        url:"functions/add_recipe.php",
        dataType:"json",
        data:{
            'pasi':pasi
        },
        success: function(data){
    
        },
        error: function(){
            alert('error');
        }
    });
    
    return false;
     }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料