Chciałbym złączyć wszystkie aktualności z tych stron i wyświetlić na stronie głównej.
Struktura tabel tych newsów jest taka sama dla wszystkich serwisów:
-- Struktura tabeli dla `internat_news` -- CREATE TABLE `glowna_news` ( `news_id` mediumint(8) UNSIGNED NOT NULL AUTO_INCREMENT, `news_subject` varchar(200) NOT NULL DEFAULT '', `news_cat` mediumint(8) UNSIGNED NOT NULL DEFAULT '0', `news_news` text NOT NULL, `news_extended` text NOT NULL, `news_breaks` char(1) NOT NULL DEFAULT '', `news_name` mediumint(8) UNSIGNED NOT NULL DEFAULT '1', `news_datestamp` int(10) UNSIGNED NOT NULL DEFAULT '0', `news_start` int(10) UNSIGNED NOT NULL DEFAULT '0', `news_end` int(10) UNSIGNED NOT NULL DEFAULT '0', `news_visibility` tinyint(3) UNSIGNED NOT NULL DEFAULT '0', `news_reads` int(10) UNSIGNED NOT NULL DEFAULT '0', `news_draft` tinyint(1) UNSIGNED NOT NULL DEFAULT '0', `news_sticky` tinyint(1) UNSIGNED NOT NULL DEFAULT '0', `news_allow_comments` tinyint(1) UNSIGNED NOT NULL DEFAULT '1', `news_allow_ratings` tinyint(1) UNSIGNED NOT NULL DEFAULT '1', PRIMARY KEY (`news_id`), KEY `news_datestamp` (`news_datestamp`), KEY `news_reads` (`news_reads`) )
Wykonując zapytanie na bazie:
SELECT * FROM `glowna_news` UNION ALL SELECT * FROM `subdomena1_news` UNION ALL SELECT * FROM `subdomena2_news` UNION ALL SELECT * FROM `subdomena3_news` ORDER BY news_datestamp DESC LIMIT 10
wszystko działa i wyświetla prawidłowe wyniki.
Mam problem z dodaniem tego do php gdyż w php tworzone są aliasy tabel a ja się na tym nie bardzo znam.
<?php ... if ($rows) { $result = dbquery( "SELECT tn.*, tc.*, user_id, user_name FROM ".DB_NEWS." tn LEFT JOIN ".DB_USERS." tu ON tn.news_name=tu.user_id LEFT JOIN ".DB_NEWS_CATS." tc ON tn.news_cat=tc.news_cat_id ORDER BY news_sticky DESC, news_datestamp DESC LIMIT ".$_GET['rowstart'].",$items_per_page" ); $numrows = dbrows($result); while ($data = dbarray($result)) { $news_cat_image = ""; $news_subject = "<a name='news_".$data['news_id']."' id='news_".$data['news_id']."'></a>".stripslashes($data['news_subject']); if ($data['news_cat_image']) { $news_cat_image = "<a href='news_cats.php?cat_id=".$data['news_cat_id']."'><img src='".get_image("nc_".$data['news_cat_name'])."' alt='".$data['news_cat_name']."' class='news-category' /></a>"; } else { $news_cat_image = ""; } $news_news = $data['news_breaks'] == "y" ? nl2br(stripslashes($data['news_news'])) : stripslashes($data['news_news']); if ($news_cat_image != "") $news_news = $news_cat_image.$news_news; "news_id" => $data['news_id'], "user_id" => $data['user_id'], "user_name" => $data['user_name'], "news_date" => $data['news_datestamp'], "news_ext" => $data['news_extended'] ? "y" : "n", "news_reads" => $data['news_reads'], "news_comments" => dbcount("(comment_id)", DB_COMMENTS, "comment_type='N' AND comment_item_id='".$data['news_id']."'"), "news_allow_comments" => $data['news_allow_comments'] ); ... ?>
Może ktoś już robił taki skrypt - bardzo by mi to pomogło.