【发布时间】:2015-09-25 23:53:11
【问题描述】:
我在 mySql 表中有一个字段,即 Expanse 和另一个名为 Amount 的字段。
现在我想在';'的基础上打破expanse和amount字段中的字符串并将每个记录存储为单独的记录,以便其他字段(即 id 和 name)中的数据保持不变。这样
我正在从原始表中获取记录,并希望将这个所需的结果存储在临时表中。在从原始表中获取记录时,我在';'的基础上爆炸了扩展和数量字符串。
$query="SELECT * FROM table";
$result=mysql_query($query);
while ($row=mysql_fetch_array($result))
{
$newid=$row["id"];
$temp=explode(';',$row["expanse"]);
$new=array_unique($temp);
//what to do after this ?
$temp2=explode(';',$row["amount"]);
$new2=array_unique($temp2);
//what to do after this ?
$query2="INSERT INTO table2 (id, $expanse,$amount) VALUES ('$newid','$new',$new2);
$result2=mysql_query($query2);
}
//after this i'll be inserting values in these variables into new temporary table that is having same structure so that my orignal data remain unchanged and new data as my need inserted into temporary table.
希望你能得到我的问题。
【问题讨论】:
-
在 $result2 写入第二个查询以插入临时数据之后。
-
您可以根据需要保存它,但如果
id是primary key那么它将始终是唯一的
标签: php mysql arrays optimization