简体   繁体   English

将同名的多个输入插入一个数组[行](以“^”分隔)

[英]Insert multiple inputs with same name, into one array [row] (separated by "^")

I have multiple inputs (never being the same, because it's a dynamic add/remove jquery script, and it is all dependent on how many "tracks" the user wants to enter).我有多个输入(永远不会相同,因为它是一个动态添加/删除 jquery 脚本,它完全取决于用户想要输入多少“曲目”)。 I WILL NEVER KNOW HOW MANY WILL BE THERE.我永远不知道那里会有多少人。 Below is an example of if a user chooses to add four "tracks" to their "mixtape".下面是一个示例,说明用户是否选择将四个“曲目”添加到他们的“混音带”。

<input size="32" class="mixtapetrack" type="textbox" id="track[1]" name="track[]" >
<input size="32" class="mixtapetrack" type="textbox" id="track[2]" name="track[]" >
<input size="32" class="mixtapetrack" type="textbox" id="track[3]" name="track[]" >
<input size="32" class="mixtapetrack" type="textbox" id="track[4]" name="track[]" >

When the form is submited (PHP POSTED), I want to take all of the inputs and combine them into one array, but sepparating them all by "^^^" .提交表单时(PHP POSTED),我想获取所有输入并将它们组合成一个数组,但将它们全部分开"^^^"


This is what I have so far, for rendering out the inputs (NOT WORKING).这是我目前所拥有的,用于渲染输入(不工作)。

$trackVAR = $_POST['track'];

         $allmixtapetracks = "";

         foreach ($trackVAR as $value) {

    $allmixtapetracks .= '' . $value . '^';
  }

And This is what i'm using to insert into my table (WORKS, tested it without the variable and entered absoloute data)这就是我用来插入到我的表中的内容(WORKS,在没有变量的情况下对其进行了测试并输入了绝对数据)

$sql = mysql_query("INSERT INTO mixtapes (title, songs, posted_by_id, description, date) 
     VALUES('$mixtapetitle','$allmixtapetracks','$posted_by_id','$mixtapedescription', now())")  
     or die (mysql_error());

In the end I want it to look like this inside of the songs row最后我希望它在歌曲行中看起来像这样

Title of first song haha ^^^ Title of second song!!!第一首歌的歌名哈哈^^^第二歌的歌名!!! ^^^ The Title Of the third! ^^^第三个标题! ^^^ And The Title OF the Fourth ^^^和第四个的标题

Use implode()使用implode()

echo implode($trackVAR, " ^^^ ");

Replace your following code:替换您的以下代码:

$trackVAR = $_POST['track'];

$allmixtapetracks = "";

foreach ($trackVAR as $value) {
    $allmixtapetracks .= '' . $value . '^';
}

with this:有了这个:

$allmixtapetracks=implode('^^^',$_POST['track']);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 MySql 中的一个单元格中插入多个具有相同名称的文本输入 - Insert multiple text inputs with same name, into one cell in MySql 如何将多个输入插入按相同数据分组的同一行 - How to insert multiple inputs into the same row that group by the same data 如何通过Ajax在php中插入具有相同名称的多个输入 - How to insert multiple inputs with same name in php through ajax 在 xml 和 php 多个同名输入中创建一个 - create one in xml with php multiple inputs with same name 如何在具有不同字段名称的一行中插入数组复选框的多个值 - how to insert multiple values of array checkbox in one row with different field name 序列化数组将输入相同名称 - serialise array will inputs of same name 我的问题是我在一行中插入了多个图像,并在codeginter中用逗号分隔 - my issue is that i insert multiple image in one row with comma separated in codeginter 如何在数据库中插入多个输入的数组? - How can insert array of multiple inputs in database? 如何在表的同一列的多行中从单一格式插入相同名称的多个数据 - How to insert multiple data of same name from single form in multiple row of same column of table 将多个具有相同名称的输入添加到mysql数据库 - Add multiple inputs with same name to mysql database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM