[英]Storing in same id of database
I have this form to allow users to insert multiple phone types and multiple emails: 我有此表格,允许用户插入多种电话类型和多种电子邮件:
<div id="dynamicInput">
<input type="text" name="mytype[]" placeholder="Phone Type"> <input type="text" name="myinputs[]" id="phone" placeholder="Phone Number">
<span class="glyphicon glyphicon-plus" onClick="addInput('dynamicInput');"></span>
<br> </div><br>
And in the controller i have this piece of code: 在控制器中,我有这段代码:
foreach($myinputs as $myinput)
{
$phone=new phone();
$phone->secondary_phones=$myinput;
$phone->id=$getlast;
$phone->save();
}
foreach($mytype as $mytypes)
{
$phone=new phone();
$phone->id=$getlast;
$phone->secondary_phones_type=$mytypes;
$phone->save();
}
$getlast
is the id from another table. $getlast
是另一个表的ID。
the problem here is phone types and phone numbers are added in the separate phone_id
. 这里的问题是电话类型和电话号码添加在单独的
phone_id
。 what I want is respective phone type and phone number to be inserted in same phone_id
. 我想要的是将各自的电话类型和电话号码插入相同的
phone_id
。 phone_id
is auto increment primary key. phone_id
是自动递增主键。 I have secondary_phones
and secondary_phones_type
as the database columns, I guess the problem is with saving in database differently for phone number and phone type. 我有
secondary_phones
和secondary_phones_type
作为数据库列,我想问题是出在电话号码和电话类型上以不同的方式保存在数据库中。
If you have same number of inputs for phone types and phone numbers than you can try it. 如果电话类型和电话号码 的输入数量相同,则可以尝试。
for($i=0;$i<$myinputs.length;$i++)
{
$phone=new phone();
$phone->secondary_phones=$myinputs[$i];
$phone->secondary_phones_type=$mytype[$i];
$phone->id=$getlast;
$phone->save();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.