我有这个问题,希望有人可以帮助我。我需要在表格的列中插入我输入的4个数据,但事情是我不知道如何。
以下是我从输入框中获取数据的方法:
$restdaymul1 = $this->input->get('restmul1');
$restdaymul2 = $this->input->get('restmul2');
$restdaymul3 = $this->input->get('restmul3');
$restdaymul4 = $this->input->get('restmul4');
我想将输入的数据插入表中的一列(restday) 我的表看起来像这样:
----------------------------------
id | restdaytype | restdaymul |
1 | 1 | |
2 | 3 | |
3 | 5 | |
4 | 1 | |
如何将数据插入到restdaymul列。
答案 0 :(得分:1)
如果您想使用array
for loop
执行此操作
$restdaymul[0] = $this->input->get('restmul1');
$restdaymul[1] = $this->input->get('restmul2');
$restdaymul[2] = $this->input->get('restmul3');
$restdaymul[3] = $this->input->get('restmul4');
$arrlength=count($restdaymul);
for($x=0;$x<$arrlength;$x++)
{
$query = "INSERT INTO restday (restdaymul) VALUES ($restdaymul[$x])";
mysql_query($query);
}
您也可以使用foreach
代替for loop
。
foreach($restdaymul as $values)
{
$query = "INSERT INTO restday (restdaymul) VALUES ($values])";
mysql_query($query);
}
我应该研究sql queries。
插入查询的语法为:
INSERT INTO YourTableName (YourTableColumnName) VALUES (YourValue);
答案 1 :(得分:0)
你也可以尝试这个
$restdaymul[0] = $this->input->get('restmul1');
$restdaymul[1] = $this->input->get('restmul2');
$restdaymul[2] = $this->input->get('restmul3');
$restdaymul[3] = $this->input->get('restmul4');
foreach($restdaymul as $data)
{
$query = "Insert into tbl_name (restdaytype) values ($data)";
}