This is my rss.php file for rss feed the problem I encounter is that - I can select only one table from database at a time,I know about joins but I don't have anything in common,moreover I want that it should select random table from database and then fetch its respective title,content and summary,Is there some way to do that,just like we can use rand() function (order by rand()) something like this,so that I can get random table from database in select * query.So that I can have mixed rss feeds from all the tables.
<?php
function connect() {
return new PDO('mysql:host=localhost;dbname=jossicoa_writeups', 'root', '', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
}
$pdo = connect();
$sql = 'SELECT * FROM scienceandtechnology';
$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>Jossips</title>';
$data .= '<link>http://www.google.com</link>';
$data .= '<description>various section</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;
?>
Try something like this.
$myarray = array('tbl1','tbl2','tbl3','tbl4');
// get random value from array
$key = array_rand($myarray);
$table= $myarray[$key];
Then you can run your sql query...
select * from $table ...