gpt4 book ai didi

php - ajax调用php并从mysql表返回数据。热衷于制作这样的数据结构吗?

转载 作者:行者123 更新时间:2023-11-29 17:34:42 25 4
gpt4 key购买 nike

我对php文件进行ajax调用,该文件必须读取mysql并返回这样的数据结构。如何制作?

[{"ID":null,"0":null,"TimeID":"2","1":"2","MyToDate":null,"2":null,"MyDayOfW":"0","3":"0","WtTimeFrom":"01:30:00","4":"01:30:00","WtTimeTo":"03:00:00","5":"03:00:00","EntryDate":"2018:05:17 05:44:53.906","6":"2018:05:17 05:44:53.906"},{"ID":null,"0":null,"TimeID":"2","1":"2","MyToDate":null,"2":null,"MyDayOfW":"1","3":"1","WtTimeFrom":"06:00:00","4":"06:00:00","WtTimeTo":"06:30:00","5":"06:30:00","EntryDate":"2018:05:17 05:44:53.906","6":"2018:05:17 05:44:53.906"},{"ID":null,"0":null,"TimeID":"2","1":"2","MyToDate":null,"2":null,"MyDayOfW":"1","3":"1","WtTimeFrom":"07:00:00","4":"07:00:00","WtTimeTo":"07:30:00","5":"07:30:00","EntryDate":"2018:05:17 05:44:53.906","6":"2018:05:17 05:44:53.906"},{"ID":null,"0":null,"TimeID":"2","1":"2","MyToDate":null,"2":null,"MyDayOfW":"1","3":"1","WtTimeFrom":"07:30:00","4":"07:30:00","WtTimeTo":"08:00:00","5":"08:00:00","EntryDate":"2018:05:17 05:44:53.906","6":"2018:05:17 05:44:53.906"},{"ID":null,"0":null,"TimeID":"2","1":"2","MyToDate":null,"2":null,"MyDayOfW":"1","3":"1","WtTimeFrom":"08:00:00","4":"08:00:00","WtTimeTo":"08:30:00","5":"08:30:00","EntryDate":"2018:05:17 05:44:53.906","6":"2018:05:17 05:44:53.906"},{"ID":null,"0":null,"TimeID":"2","1":"2","MyToDate":null,"2":null,"MyDayOfW":"2","3":"2","WtTimeFrom":"03:00:00","4":"03:00:00","WtTimeTo":"05:00:00","5":"05:00:00","EntryDate":"2018:05:17 05:44:53.906","6":"2018:05:17 05:44:53.906"},{"ID":null,"0":null,"TimeID":"2","1":"2","MyToDate":null,"2":null,"MyDayOfW":"2","3":"2","WtTimeFrom":"07:30:00","4":"07:30:00","WtTimeTo":"12:30:00","5":"12:30:00","EntryDate":"2018:05:17 05:44:53.906","6":"2018:05:17 05:44:53.906"},{"ID":null,"0":null,"TimeID":"2","1":"2","MyToDate":null,"2":null,"MyDayOfW":"3","3":"3","WtTimeFrom":"03:00:00","4":"03:00:00","WtTimeTo":"04:30:00","5":"04:30:00","EntryDate":"2018:05:17 05:44:53.906","6":"2018:05:17 05:44:53.906"},{"ID":null,"0":null,"TimeID":"2","1":"2","MyToDate":null,"2":null,"MyDayOfW":"3","3":"3","WtTimeFrom":"07:30:00","4":"07:30:00","WtTimeTo":"11:30:00","5":"11:30:00","EntryDate":"2018:05:17 05:44:53.906","6":"2018:05:17 05:44:53.906"},{"ID":null,"0":null,"TimeID":"2","1":"2","MyToDate":null,"2":null,"MyDayOfW":"3","3":"3","WtTimeFrom":"12:00:00","4":"12:00:00","WtTimeTo":"12:30:00","5":"12:30:00","EntryDate":"2018:05:17 05:44:53.906","6":"2018:05:17 05:44:53.906"},{"ID":null,"0":null,"TimeID":"2","1":"2","MyToDate":null,"2":null,"MyDayOfW":"3","3":"3","WtTimeFrom":"13:00:00","4":"13:00:00","WtTimeTo":"13:30:00","5":"13:30:00","EntryDate":"2018:05:17 05:44:53.906","6":"2018:05:17 05:44:53.906"},{"ID":null,"0":null,"TimeID":"2","1":"2","MyToDate":null,"2":null,"MyDayOfW":"3","3":"3","WtTimeFrom":"14:30:00","4":"14:30:00","WtTimeTo":"15:00:00","5":"15:00:00","EntryDate":"2018:05:17 05:44:53.906","6":"2018:05:17 05:44:53.906"},{"ID":null,"0":null,"TimeID":"2","1":"2","MyToDate":null,"2":null,"MyDayOfW":"4","3":"4","WtTimeFrom":"07:00:00","4":"07:00:00","WtTimeTo":"09:30:00","5":"09:30:00","EntryDate":"2018:05:17 05:44:53.906","6":"2018:05:17 05:44:53.906"},{"ID":null,"0":null,"TimeID":"2","1":"2","MyToDate":null,"2":null,"MyDayOfW":"4","3":"4","WtTimeFrom":"03:00:00","4":"03:00:00","WtTimeTo":"03:30:00","5":"03:30:00","EntryDate":"2018:05:17 05:44:53.906","6":"2018:05:17 05:44:53.906"}]

和我的 php 文件:

$con = mssql_connect($myServer, $myUser, $myPass) or die("Could not connect to database: ".mssql_get_last_message()); 
if($con){
// echo "connected";
}
// Select a database:
mssql_select_db('DB')
or die('Could not select a database.');

$SQL = "SELECT * FROM Details WHERE ID='2'";

// Execute query:
$result = mssql_query($SQL)
or die('A error occured: ' . mysql_error());

如何在php中制作echo这样的数据结构?

最佳答案

数据结构是有效的 JSON 字符串。

[{"ID":null,"0":null,"TimeID":"2","1":"2","MyToDate":null,"2":null,"MyDayOfW":"0","3":"0","WtTimeFrom":"01:30:00","4":"01:30:00","WtTimeTo":"03:00:00","5":"03:00:00","EntryDate":"2018:05:17 05:44:53.906","6":"2018:05:17 05:44:53.906"},{"ID":null,"0":null,"TimeID":"2","1":"2","MyToDate":null,"2":null,"MyDayOfW":"1","3":"1","WtTimeFrom":"06:00:00","4":"06:00:00","WtTimeTo":"06:30:00","5":"06:30:00","EntryDate":"2018:05:17 05:44:53.906","6":"2018:05:17 05:44:53.906"},{"ID":null,"0":null,"TimeID":"2","1":"2","MyToDate":null,"2":null,"MyDayOfW":"1","3":"1","WtTimeFrom":"07:00:00","4":"07:00:00","WtTimeTo":"07:30:00","5":"07:30:00","EntryDate":"2018:05:17 05:44:53.906","6":"2018:05:17 05:44:53.906"},{"ID":null,"0":null,"TimeID":"2","1":"2","MyToDate":null,"2":null,"MyDayOfW":"1","3":"1","WtTimeFrom":"07:30:00","4":"07:30:00","WtTimeTo":"08:00:00","5":"08:00:00","EntryDate":"2018:05:17 05:44:53.906","6":"2018:05:17 05:44:53.906"},{"ID":null,"0":null,"TimeID":"2","1":"2","MyToDate":null,"2":null,"MyDayOfW":"1","3":"1","WtTimeFrom":"08:00:00","4":"08:00:00","WtTimeTo":"08:30:00","5":"08:30:00","EntryDate":"2018:05:17 05:44:53.906","6":"2018:05:17 05:44:53.906"},{"ID":null,"0":null,"TimeID":"2","1":"2","MyToDate":null,"2":null,"MyDayOfW":"2","3":"2","WtTimeFrom":"03:00:00","4":"03:00:00","WtTimeTo":"05:00:00","5":"05:00:00","EntryDate":"2018:05:17 05:44:53.906","6":"2018:05:17 05:44:53.906"},{"ID":null,"0":null,"TimeID":"2","1":"2","MyToDate":null,"2":null,"MyDayOfW":"2","3":"2","WtTimeFrom":"07:30:00","4":"07:30:00","WtTimeTo":"12:30:00","5":"12:30:00","EntryDate":"2018:05:17 05:44:53.906","6":"2018:05:17 05:44:53.906"},{"ID":null,"0":null,"TimeID":"2","1":"2","MyToDate":null,"2":null,"MyDayOfW":"3","3":"3","WtTimeFrom":"03:00:00","4":"03:00:00","WtTimeTo":"04:30:00","5":"04:30:00","EntryDate":"2018:05:17 05:44:53.906","6":"2018:05:17 05:44:53.906"},{"ID":null,"0":null,"TimeID":"2","1":"2","MyToDate":null,"2":null,"MyDayOfW":"3","3":"3","WtTimeFrom":"07:30:00","4":"07:30:00","WtTimeTo":"11:30:00","5":"11:30:00","EntryDate":"2018:05:17 05:44:53.906","6":"2018:05:17 05:44:53.906"},{"ID":null,"0":null,"TimeID":"2","1":"2","MyToDate":null,"2":null,"MyDayOfW":"3","3":"3","WtTimeFrom":"12:00:00","4":"12:00:00","WtTimeTo":"12:30:00","5":"12:30:00","EntryDate":"2018:05:17 05:44:53.906","6":"2018:05:17 05:44:53.906"},{"ID":null,"0":null,"TimeID":"2","1":"2","MyToDate":null,"2":null,"MyDayOfW":"3","3":"3","WtTimeFrom":"13:00:00","4":"13:00:00","WtTimeTo":"13:30:00","5":"13:30:00","EntryDate":"2018:05:17 05:44:53.906","6":"2018:05:17 05:44:53.906"},{"ID":null,"0":null,"TimeID":"2","1":"2","MyToDate":null,"2":null,"MyDayOfW":"3","3":"3","WtTimeFrom":"14:30:00","4":"14:30:00","WtTimeTo":"15:00:00","5":"15:00:00","EntryDate":"2018:05:17 05:44:53.906","6":"2018:05:17 05:44:53.906"},{"ID":null,"0":null,"TimeID":"2","1":"2","MyToDate":null,"2":null,"MyDayOfW":"4","3":"4","WtTimeFrom":"07:00:00","4":"07:00:00","WtTimeTo":"09:30:00","5":"09:30:00","EntryDate":"2018:05:17 05:44:53.906","6":"2018:05:17 05:44:53.906"},{"ID":null,"0":null,"TimeID":"2","1":"2","MyToDate":null,"2":null,"MyDayOfW":"4","3":"4","WtTimeFrom":"03:00:00","4":"03:00:00","WtTimeTo":"03:30:00","5":"03:30:00","EntryDate":"2018:05:17 05:44:53.906","6":"2018:05:17 05:44:53.906"}]

尝试使用 JSON 对结果数据进行编码。

json_encode($result);

关于php - ajax调用php并从mysql表返回数据。热衷于制作这样的数据结构吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50388437/

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