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条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测