$NI0=trim($_POST["NI0"]);
$NI1=trim($_POST["NI1"]);
$NI2=trim($_POST["NI2"]);
$NI3=trim($_POST["NI3"]);
$NI4=trim($_POST["NI4"]);
$NI5=trim($_POST["NI5"]);
$NI6=trim($_POST["NI6"]);
$NI7=trim($_POST["NI7"]);
$NI8=trim($_POST["NI8"]);
$NI9=trim($_POST["NI9"]);
$no0=trim($_POST["no0"]);
$no1=trim($_POST["no1"]);
$no2=trim($_POST["no2"]);
$no3=trim($_POST["no3"]);
$no4=trim($_POST["no4"]);
$no5=trim($_POST["no5"]);
$no6=trim($_POST["no6"]);
$no7=trim($_POST["no7"]);
$no8=trim($_POST["no8"]);
$no9=trim($_POST["no9"]);
我获取过来的记录是这样的,我怎么循环添加到数据库中呢?请高手赐教……如果用的是insert into 这个添加的话,我要写的东西实在是太多了,老是出错,请高手提供一个便捷的方式添加记录代码……在线等候
$NI1=trim($_POST["NI1"]);
$NI2=trim($_POST["NI2"]);
$NI3=trim($_POST["NI3"]);
$NI4=trim($_POST["NI4"]);
$NI5=trim($_POST["NI5"]);
$NI6=trim($_POST["NI6"]);
$NI7=trim($_POST["NI7"]);
$NI8=trim($_POST["NI8"]);
$NI9=trim($_POST["NI9"]);
$no0=trim($_POST["no0"]);
$no1=trim($_POST["no1"]);
$no2=trim($_POST["no2"]);
$no3=trim($_POST["no3"]);
$no4=trim($_POST["no4"]);
$no5=trim($_POST["no5"]);
$no6=trim($_POST["no6"]);
$no7=trim($_POST["no7"]);
$no8=trim($_POST["no8"]);
$no9=trim($_POST["no9"]);
我获取过来的记录是这样的,我怎么循环添加到数据库中呢?请高手赐教……如果用的是insert into 这个添加的话,我要写的东西实在是太多了,老是出错,请高手提供一个便捷的方式添加记录代码……在线等候
{
$NI[$i]=trim($_POST['NI'.$i]);
echo $name[$i];
}
for($i=0;$i<=$num-1;$i++)
{
$no[$i]=trim($_POST['no'.$i]);
echo $name[$i];
}
去怎么通过这个循环添加到数据中呢?
for($i=0;$i <=$num-1;$i++)
{
$NI[$i]=trim($_POST['NI'.$i]);
$no[$i]=trim($_POST[no'.$i]);
$db->query("INSERT INTO table (ni,no) VALUES('$NI[$i]','$no[$i]')");
}
是这样吗?
这个不都是吧记录都放到这个ni字段下面了啊
{
$NI[$i]=trim($_POST['NI'.$i]);
$no[$i]=trim($_POST[no'.$i]);
$db->query("INSERT INTO table (ni[$i],no[$i]) VALUES('$NI[$i]','$no[$i]')");
}
改成这样不知道可不可以
{
$NI[$i]="'".trim($_POST['NI'.$i])."'";
$no[$i]="'".trim($_POST[no'.$i])."'";
$filedNi[$i] = 'ni'.$i;
$filedNo[$i] = 'no'.$i;
}
$sql = "INSERT INTO table(".join(",",$filedNi).",".join(",",$filedNo).") VALUES(".join(",",$NI).",".join(",",$no).")";
$db->query($sql);