gpt4 book ai didi

mysql - 使用 mysql 在列之间移动数据的 php 脚本

转载 作者:行者123 更新时间:2023-11-29 00:31:05 25 4
gpt4 key购买 nike

我想要实现的是在一个表中的 2 行之间移动数据。

Column A
--------
FN2
1 200x310mm
2 400x260mm[+0.84]
3 500x500mm[+11.34]

Column B
--------
0.0000
0.0000
0.0000
0.0000

这是数据移动后的样子:

Column A
--------
FN2
1 200x310mm
2 400x260mm
3 500x500mm

Column B
--------
0.0000
0.0000
+0.84
+11.34

我想要的是将 [ ] 之间的查询移动到 B 列并替换 0.0000

我怎样才能做到这一点?

亲切的问候

最佳答案

只是为了说明 Yadav 所说的话

$query = "SELECT columnID, columnA FROM table";
$result = mysql_query($query,$conn);

while ($row = mysql_fetch_array($result)){

$id = $row['columnID'];
$a = $row['columnA'];

$pos1 = strpos($a,"[")+1;
$pos2 = strpos($a,"]");

$b = substr($a,$pos1,$pos2-$pos1);

$query = "UPDATE table SET columnB = $b WHERE columnID = $id";
mysql_query($query,$conn);


}//end while

编辑:当我输入我的答案时,Yadav 显然提出了一个更好的答案......

关于mysql - 使用 mysql 在列之间移动数据的 php 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16484629/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com