【发布时间】:2020-02-26 19:41:14
【问题描述】:
我有一个字符串,我需要将此信息放入数据库。
我不确定操作字符串以与插入脚本一起使用的最佳方法。我的技能水平很低。我读过一些关于循环的文章,但不知道如何或从哪里开始。
有没有更好的方法来操作字符串以使数据库插入更容易?
非常感谢
<?php
$date = $_SESSION['date'];
$string="UnAllocated,SUSY MCGRANAHAN,R,null,null;
UnAllocated,BERNADINE WASHER,A,null,null;
UnAllocated,DAVID KEHRER,R,null,null";
/*
I have been trying to break it down in the following way.
$new = preg_split("[;]", $string);
$x1=(explode(',', $new[1]));
$x2=(explode(',', $new[2]));
I would like to insert it into the following table
INSERT INTO table ("date, team, name, driver, car
values
('$date' ,'$x1[0]', '$x1[1]', '$x1[2]', '$x1[3]'),
('$date' ,'$x2[0]', '$x2[1]', '$x2[2]', '$x2[3]')");
*/
Table
| date | team | name | driver | car |
---------------------------------------------------------
| cur | unallocated | SUSY.. | A | null |
| cur | unallocated | BERN...| R | null |
【问题讨论】:
-
您的问题到底是什么?
-
$string 你的数据是如何格式化的?提出这个问题的最好方法是向我们展示您拥有的数据是如何格式化的,并向我们展示您想要拥有的表格。然后就很容易将数据放入表中。