PHP怎么 实现批量添加数据
下面这个是栏目添加,怎么把它改为批量添加publicfunctionadd(){$city_list=M("DealCity")->where('is_delete=0'...
下面这个是栏目添加,怎么把它改为批量添加
public function add()
{
$city_list = M("DealCity")->where('is_delete = 0')->findAll();
$city_list = D("DealCity")->toFormatTree($city_list,'name');
$this->assign("city_list",$city_list);
$this->assign("new_sort", M("Area")->max("sort")+1);
$this->display();
}
<tr>
<td class="item_title">名称</td>
<td class="item_input"><input type="text" class="textbox require" name="name" /></td>
</tr> 展开
public function add()
{
$city_list = M("DealCity")->where('is_delete = 0')->findAll();
$city_list = D("DealCity")->toFormatTree($city_list,'name');
$this->assign("city_list",$city_list);
$this->assign("new_sort", M("Area")->max("sort")+1);
$this->display();
}
<tr>
<td class="item_title">名称</td>
<td class="item_input"><input type="text" class="textbox require" name="name" /></td>
</tr> 展开
2个回答
2015-05-03
展开全部
在HTML里这样写:
1
2
3
4
5
6
<form ........
<input type="text" name="haoma[]" />
<input type="text" name="haoma[]" />
<input type="text" name="haoma[]" />
....
第N个
foreach($_POST['haoma'] as $v){
$sql="insert into haoma values('',$v)";
.......
}
当然这样写一条一条的效率是会慢,再改一下
foreach($_POST['haoma'] as $v){
$values.="('',$v),";
}
$values=substr($values,0,strlen($values)-1);
$sql="insert into haoma values $values";
......
下面的query我就不写了
1
2
3
4
5
6
<form ........
<input type="text" name="haoma[]" />
<input type="text" name="haoma[]" />
<input type="text" name="haoma[]" />
....
第N个
foreach($_POST['haoma'] as $v){
$sql="insert into haoma values('',$v)";
.......
}
当然这样写一条一条的效率是会慢,再改一下
foreach($_POST['haoma'] as $v){
$values.="('',$v),";
}
$values=substr($values,0,strlen($values)-1);
$sql="insert into haoma values $values";
......
下面的query我就不写了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询