我的代码现在看起来如何
$client = $_GET['client_number_search'];
$sql=("SELECT * FROM tobytemp.fcl_reports WHERE client_number = '" . $client . "'");
$result = $dbLink->query($sql);
$arr = array();
while ($r = $result->fetch_object()) {
$temp=[
"client_number" => $r->client_number,
"client_name" => $r->client_name,
"service" => unserialize($r->service),
"volume" => $r->volume,
"deliver_point" => $r->deliver_point,
"port_orgin" => $r->port_orgin,
"size" => $r->size
];
array_push($arr,$temp);
}
echo json_encode($arr);
/* ERROR
Request Method:GET
Status Code:500 Internal Server Error
*/
当前数据填充在我的表格中 -
service - a:2:{i:0;s:6:"Inport";i:1;s:6:"Export";}
我希望它能显示为 -
Service-
Import
Export
(我不能在MY clientreports.html
页面上使用PHP,因为我想稍后将其用作手机间隙的APP)。
AJAX CALL(clientreports.html)
<script type="text/javascript">
$("#show_clientx").click(function(e) {
$("table#client_profile").empty();
$.ajax({
url: "http://cmlsys/toby/client_profile.php?client_number_search=" + $("#client_number").val(),
type: "GET",
dataType: "json",
success: function(html) {
// $("table#client_profile").append('<tr><th>Client Number</th><th>Client Name</th><th>Address</th></tr>');
jQuery.each(html, function(key, value) {
$("table#client_profile").append('<tr><td>' + value.client_number + '</td><td> client_name - ' + value.client_name + '</td></tr><tr></br><td>service - ' + value.service + '</td></br><td>size - ' + value.size + '</td></br><td>volume - ' + value.volume + '</td></br><td>deliver_point -' + value.deliver_point + '</td></br><td>port_orgin - ' + value.port_orgin + '</td></tr>');
});
},
error: function(e) {
console.log("Error: " + e);
}
});
});
</script>
TO - client_profile.php
$client = $_GET['client_number_search'];
$sql = ("SELECT * FROM tobytemp.fcl_reports WHERE client_number = '".$client.
"'");
$result = $dbLink - > query($sql);
$arr = array();
while ($r = $result - > fetch_object()) {
array_push($arr, array("client_number" => $r - > client_number, "client_name" => $r - > client_name, "service" => $r - > service, "size" => $r - > size, "volume" => $r - > volume, "deliver_point" => $r - > deliver_point, "port_orgin" => $r - > port_orgin));
}
echo json_encode($arr);
请帮助
答案 0 :(得分:3)
在php中使用unserialize
例如
while ($r = $result->fetch_object()) {
$temp=[
"client_number" => $r->client_number,
"client_name" => $r->client_name,
"service" => unserialize($r->service),
"volume" => $r->volume,
"deliver_point" => $r->deliver_point,
"port_orgin" => $r->port_orgin,
"size" => $r->size
];
array_push($arr,$temp);
}
您的代码可以在循环时更改
$('.reward_select').change(function(){
console.log$(this).parent().next().children().val());
console.log$(this).parent().next().next().children().val());
});
答案 1 :(得分:2)
UIAlertController