将API结果转换为HTML表
我一直在尝试在HTML表中获得API结果,但无法做到同样的事情。当我回显API响应时,它会非常完美,但在HTML表中呈现时,它会被创建将API结果转换为HTML表,html,twitter-bootstrap,datatable,html-table,Html,Twitter Bootstrap,Datatable,Html Table,我一直在尝试在HTML表中获得API结果,但无法做到同样的事情。当我回显API响应时,它会非常完美,但在HTML表中呈现时,它会被创建和,显示总结果,甚至创建分页,但结果不会显示。我的意思是,它显示的是空白表 另外,我正在尝试在数据表中获取结果 代码:- <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA
和
,显示总结果,甚至创建分页,但结果不会显示。我的意思是,它显示的是空白表
另外,我正在尝试在数据表中获取结果
代码:-
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap 101 Template</title>
<link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css">
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/plug-ins/9dcbecd42ad/integration/bootstrap/3/dataTables.bootstrap.css">
<script type="text/javascript" language="javascript" src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript" language="javascript" src="//cdn.datatables.net/1.10.3/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" language="javascript" src="dataTables.bootstrap.js"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('#example').dataTable();
} );
</script>
<!-- Bootstrap
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">-->
<!-- Optional theme
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css">-->
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<style>
/*.filterable {
margin-top: 15px;
}
.filterable .panel-heading .pull-right {
margin-top: -20px;
}
.filterable .filters input[disabled] {
background-color: transparent;
border: none;
cursor: auto;
box-shadow: none;
padding: 0;
height: auto;
}
.filterable .filters input[disabled]::-webkit-input-placeholder {
color: #333;
}
.filterable .filters input[disabled]::-moz-placeholder {
color: #333;
}
.filterable .filters input[disabled]:-ms-input-placeholder {
color: #333;
}
*/
</style>
</head>
<body>
<div class="container">
<?php
error_reporting(0);
// Specify API URL
define('HASOFFERS_API_URL', 'http://api.hasoffers.com/Apiv3/json');
// Specify method arguments
$args = array(
'NetworkId' => 'abc',
'Target' => 'Report',
'Method' => 'getConversions',
'NetworkToken' => 'NETkHhcasadzxcFYRnvsrtertKvh',
'fields' => array(
'Offer.name',
'Stat.ad_id',
'Stat.affiliate_id',
'Stat.advertiser_info',
'Stat.affiliate_info1',
'Stat.status',
'Stat.session_ip',
'Stat.datetime',
'Stat.datetime_diff'
),
'filters' => array(
'Stat.affiliate_id' => array(
'conditional' => 'EQUAL_TO',
'values' => '2'
)
),
'data_start' => '2015-09-01',
'data_end' => '2015-09-01'
);
// Initialize cURL
$curlHandle = curl_init();
// Configure cURL request
curl_setopt($curlHandle, CURLOPT_URL, HASOFFERS_API_URL . '?' . http_build_query($args));
// Make sure we can access the response when we execute the call
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
// Execute the API call
$jsonEncodedApiResponse = curl_exec($curlHandle);
// Ensure HTTP call was successful
if($jsonEncodedApiResponse === false) {
throw new \RuntimeException(
'API call failed with cURL error: ' . curl_error($curlHandle)
);
}
// Clean up the resource now that we're done with cURL
curl_close($curlHandle);
// Decode the response from a JSON string to a PHP associative array
$apiResponse = json_decode($jsonEncodedApiResponse, true);
// Make sure we got back a well-formed JSON string and that there were no
// errors when decoding it
$jsonErrorCode = json_last_error();
if($jsonErrorCode !== JSON_ERROR_NONE) {
throw new \RuntimeException(
'API response not well-formed (json error code: ' . $jsonErrorCode . ')'
);
}
// Print out the response details
if($apiResponse['response']['status'] === 1) {
// No errors encountered
echo 'API call successful';
echo PHP_EOL;
echo 'Response Data: ' . print_r($apiResponse['response']['data'], true);
echo PHP_EOL;
}
else {
// An error occurred
echo 'API call failed (' . $apiResponse['response']['errorMessage'] . ')';
echo PHP_EOL;
echo 'Errors: ' . print_r($apiResponse['response']['errors'], true);
echo PHP_EOL;
}
?>
</div>
<div class="container">
<h3>Affiliates Details</h3>
<p><span>Total Records:-<?php print_r($apiResponse['response']['data']['count']); ?></span></p>
<hr>
<table class="table table-striped table-bordered" id="example">
<thead>
<tr class="filters">
<th>Affiliate Id</th>
<th>Offer ID</th>
<th>Status</th>
<th>Session IP</th>
<th>Transaction ID</th>
<th>Adv info</th>
<th>Aff Info</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<?php
foreach($apiResponse['response']['data'] as $x =>$x_value) {
// echo "Affiliate ID" . $x . ", Value=" ;
//print_r($x_value);
foreach($x_value as $x => $x_value) {
$sss = $x_value['Stat.affiliate_id'];
echo "<tr>";
echo "<td style='width:50px;'>".$x_value['Stat.affiliate_id']."</td>";
echo "<td>".$x_value['Offer.name']."</td>";
echo "<td>".$x_value['Stat.status']."</td>";
echo "<td>".$x_value['Stat.session_ip']."</td>";
echo "<td>".$x_value['Stat.ad_id']."</td>";
echo "<td>".$x_value['Stat.advertiser_info']."</td>";
echo "<td>".$x_value['Stat.affiliate_info1']."</td>";
echo "<td>".$x_value['Stat.datetime']."</td>";
echo "</tr>";
}
}
?>
</tbody>
</table>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>-->
<!-- Include all compiled plugins (below), or include individual files as needed
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>-->
</body>
</html>
引导101模板
$(文档).ready(函数(){
$(“#示例”).dataTable();
} );
/*.可过滤{
边缘顶部:15px;
}
.可过滤。面板标题。向右拉{
利润上限:-20px;
}
.filterable.filters输入[禁用]{
背景色:透明;
边界:无;
光标:自动;
盒影:无;
填充:0;
高度:自动;
}
.filterable.filters输入[已禁用]:-webkit输入占位符{
颜色:#333;
}
.filterable.filters输入[禁用]:-moz占位符{
颜色:#333;
}
.filterable.filters输入[禁用]:-ms输入占位符{
颜色:#333;
}
*/
所以你在body标签外有html代码?原因是什么?您是否尝试验证html代码,因为您所做的是invalid@NullPoi我没有尝试过验证html,但是相同的代码使用不同的API。html代码仅在body标记中。