Rss提要不显示从所有的表
Rss feed not showing from all the tables
我使用这个rss.php文件的rss提要,但问题是,它显示饲料从只有2个表,而不是所有的4。问题在哪里?饲料来自名人和经济和政治表。
<?php
function connect() {
return new PDO('mysql:host=localhost;dbname=wg','root','', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
}
$pdo = connect();
$myarray = array('scienceandtechnology','economicsandpolitics','famouspeople','yetosbkistoryhe');
$key = array_rand($myarray);
$table= $myarray[$key];
$sql = "SELECT * FROM ".$table."";
$query = $pdo->prepare($sql);
$query->execute();
$rs_post = $query->fetchAll();
// The XML structure
$data = '<?xml version="1.0" encoding="UTF-8" ?>';
$data .= '<rss version="2.0">';
$data .= '<channel>';
$data .= '<title>google</title>';
$data .= '<link>http://www.google.com</link>';
$data .= '<description>io</description>';
foreach ($rs_post as $row) {
$data .= '<item>';
$data .= '<title>'.$row['title'].'</title>';
$data .= '<link>'.$row['content'].'</link>';
$data .= '<description>'.$row['summary'].'</description>';
$data .= '</item>';
}
$data .= '</channel>';
$data .= '</rss> ';
header('Content-Type: application/xml');
echo $data;
?>
你在这里从表名静态使用它我有几乎相同的问题,但在我的情况下,表名也是动态的所以使用它根据你的相关性
$sql = mysql_query("select name from sections order by rand()");
$datadisplay = array();
while ($row= mysql_fetch_assoc($sql)){
$section=$row['name'];
$sqldata = mysql_query("select title,summary from ".$section." order by ID limit 2");
while ($rowdata= mysql_fetch_assoc($sqldata)){
$datadisplay[] = $rowdata;
}
}
这里我要做的是从section中获取表名然后使用这些表名从表中获取数据然后将这些数据存储到另一个数组中然后可以用来获取RSS数据
如果我理解正确,可能会对你有所帮助,
$pdo = connect();
$myarray = array('scienceandtechnology','economicsandpolitics','famouspeople','yetosbkistoryhe');
foreach ($myarray as $table) {
$sql = "SELECT * FROM ".$table."";
$query = $pdo->prepare($sql);
$query->execute();
$rs_post = $query->fetchAll();
foreach ($rs_post as $post) {
// echo something
}
}
相关文章:
- 无法从 jQuery RSS Feed 中的 localStorage 动态替换类
- 从桌面读取python文件时高亮显示代码
- 如何从显示提要的外部服务器或站点解析RSS URL
- Yahoo Pipes RSS pubDate在通过Google Feeds API查看时显示为“未定义”
- 如何显示来自其他网站的 RSS 源
- 如何检查RSS提要的URL是否存在,否则显示本地图像
- 在我的应用程序上显示本地RSS源
- 如何在核心PHP上显示显示来自第三方网站的RSS提要的要求
- 使用AngularJS阅读RSS提要并有条件地显示结果
- 使用javascript,我如何将rss提要放入列表中并只显示其中的4个提要
- 如何在RSS提要为空时显示文本
- Rss提要不显示从所有的表
- 在空RSS提要后显示文本
- 显示全屏img从RSS jquery
- 如何使用javascript/jquery显示带有图像的rss提要
- RSS提要完全不同于浏览器中显示的方式
- 根据标题中的关键字在RSS提要中显示博客文章
- 如何使用ionic框架显示RSS提要中的图像
- 如何更新幻灯片中显示的RSS提要
- 按时间限制ZrssFeed显示的RSS提要