我想要合并$output
和$output1
然后填充HTML表格。如何合并2个数组并在表格中打印?
这是我的代码:
<?php
$link = parse_ini_file(__DIR__ . '/config.ini', true);
include("connect.php");
$output = '';
$cnn = simplexml_load_file($link['cnn']);
$bbc = simplexml_load_file($link['bbc']);
foreach($cnn->channel->item as $item){
$title = $item->title;
$description = $item->description;
$url = $item->link;
$pubDate = $item->pubDate;
$title1 = str_replace("'","\'", $title);
$description1 = str_replace("'","\'", $description);
$output[]['title'] = $title;
$output[]['description'] = $description;
$output[]['url'] = $url;
$output[]['p_date'] = $pubDate;
$sql = mysql_query("INSERT IGNORE INTO tbl_daily_news_headlines (
title,
description,
url,
pub_date,
log_date)
VALUES (
'$title1',
'$description1',
'$url',
'$pubDate',
now())")
or die(mysql_error());
}
foreach ($bbc->channel->item as $bitem){
$bbtitle = $bitem->title;
$bbdescription = $bitem->description;
$bburl = $bitem->link;
$bbpubDate = $bitem->pubDate;
$bbtitle1 = str_replace("'", "\'", $bbtitle);
$bbdescription1 = str_replace("'", "\'", $bbdescription);
$output1[]['title'] = $bbtitle;
$output1[]['description'] = $bbdescription;
$output1[]['url'] = $bburl;
$output1[]['p_date'] = $bbpubDate;
$sql = mysql_query("INSERT IGNORE INTO tbl_daily_news_headlines(
title,
description,
url,
pub_date,
log_date)
VALUES(
'$bbtitle1',
'$bbdescription1',
'$bburl',
'$bbpubDate',now())")
or die(mysql_error());
$final_output = array_merge($output, $output1);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=2.0">
<title>Feed Example</title>
<link rel="stylesheet" type="text/css" href="media/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="media/css/dataTables.bootstrap.css">
<script type="text/javascript" language="javascript" src="media/js/jquery-1.12.0.min.js">
</script>
<script type="text/javascript" language="javascript" src="media/js/jquery.dataTables.js">
</script>
<script type="text/javascript" language="javascript" src="media/js/dataTables.bootstrap.js">
</script>
<script type="text/javascript" language="javascript" class="init">
$(document).ready(function() {
$('#example').DataTable();
});
</script>
</head>
<body class="dt-example dt-example-bootstrap">
<div class="container">
<section>
<h1>FEED Test</h1>
<div class="info">
</div>
<table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Title</th>
<th>Description</th>
<th>URL</th>
<th>Publish Date</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Title</th>
<th>Description</th>
<th>URL</th>
<th>Publish Date</th>
</tr>
</tfoot>
<tbody>
<? foreach($final_output as $data1)
{
echo '<td>'.$data1['title'].$data1['description'].$data1['url'].$data1['p_date'].'</td>';
}
?>
</tbody>
</table>
</div>
</section>
</body>
</html>
我试图array_merge()
但它不工作。
我也试过:
$data = $output + $output1;
如果我错了,我是不是放错了我的循环?
编辑: 所以之后我尝试array_merge($输出,$输出1);它只是输出数组的只是最后一个元素,第二个方法是相同的
我只是尝试做一些内部的foreach像
<? foreach($output as $data)
{
foreach($output1 as $data1)
{
echo '<td>'.$data.$data1'</td>';
}
}
?>
,但我得到500错误,所以任何想法?
编辑2: 感谢帕特里克我合并这2个输出,但仍然不能让印上表中,如果你现在的打印他们的水平(在1个泳道一切),如何让固定看我更新的代码?
“它不是WO “什么方式不起作用?你期望的结果是什么?实际结果是什么? –
检查更新后的文章 –
就错误而言,您在'echo'行的'$ data1'后面缺少'.'。 –