[英]Select the data from the updated database
In my database i have column vv that had values in ""09.12.2019 12:55:50"".在我的数据库中,我的 vv 列的值在“09.12.2019 12:55:50””中。 So i dont want remove my records and updated my data to this format 2019-12-09 12:55:50 but i am not getting any result against $result2.所以我不想删除我的记录并将我的数据更新为这种格式 2019-12-09 12:55:50 但我没有得到任何针对 $result2 的结果。 I am even not getting any error.我什至没有收到任何错误。 The input values i am selecting has data against it in database but i am getting the output in $result2.我选择的输入值在数据库中有针对它的数据,但我在 $result2 中得到输出。
<?php
include("includes\conn.php");
$start = $_POST['start_date'];
$temp_date= substr($start, 0, 10);
$temp_date1= substr($start, 11, 17);
$final= $temp_date.' '.$temp_date1;
$result = mysqli_query($con,"$result = mysqli_query($con,"UPDATE `data` SET `vv` = STR_TO_DATE(REPLACE(`vv`, '.', '-'), '%d-%m-%Y %H:%i:%s')");");
$result2 = mysqli_query($con,"SELECT * FROM data WHERE vv = '$final'");
print_r($result2);
?>
Your Kind help is needed!需要您的帮助!
Not sure what do you produce in $final
variable, but assuming you have there a string that represent some proper datetime like 2019-12-09 12:55:50
, then you need to execute the following UPDATE
query that will convert ""09.12.2019 12:55:50""
to 2019-12-09 12:55:50
strings:不确定你在$final
变量中产生了什么,但假设你有一个字符串代表一些正确的日期时间,比如2019-12-09 12:55:50
,那么你需要执行以下UPDATE
查询来转换""09.12.2019 12:55:50""
到2019-12-09 12:55:50
字符串:
UPDATE `data` SET `vv` = STR_TO_DATE(REPLACE(`vv`, '"', ''), '%d.%m.%Y %H:%i:%s')
However, executing an UPDATE
on every POST
request in order to get a SELECT
result afterwards is simply very bad approach.但是,在每个POST
请求上执行UPDATE
以在之后获得SELECT
结果是非常糟糕的方法。 Better consider to ALTER
your table and convert this nasty vv
column into real datetime
datatype format once you convert all the strings there.最好考虑ALTER
你的表,一旦你转换了所有的字符串, vv
这个讨厌的vv
列转换成真正的datetime
数据类型格式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.