Mam stronę główną i kilka subdomen z osobnym systemem newsów.
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:
  1. -- Struktura tabeli dla `internat_news`
  2. --
  3.  
  4. CREATE TABLE `glowna_news` (
  5. `news_id` mediumint(8) UNSIGNED NOT NULL AUTO_INCREMENT,
  6. `news_subject` varchar(200) NOT NULL DEFAULT '',
  7. `news_cat` mediumint(8) UNSIGNED NOT NULL DEFAULT '0',
  8. `news_news` text NOT NULL,
  9. `news_extended` text NOT NULL,
  10. `news_breaks` char(1) NOT NULL DEFAULT '',
  11. `news_name` mediumint(8) UNSIGNED NOT NULL DEFAULT '1',
  12. `news_datestamp` int(10) UNSIGNED NOT NULL DEFAULT '0',
  13. `news_start` int(10) UNSIGNED NOT NULL DEFAULT '0',
  14. `news_end` int(10) UNSIGNED NOT NULL DEFAULT '0',
  15. `news_visibility` tinyint(3) UNSIGNED NOT NULL DEFAULT '0',
  16. `news_reads` int(10) UNSIGNED NOT NULL DEFAULT '0',
  17. `news_draft` tinyint(1) UNSIGNED NOT NULL DEFAULT '0',
  18. `news_sticky` tinyint(1) UNSIGNED NOT NULL DEFAULT '0',
  19. `news_allow_comments` tinyint(1) UNSIGNED NOT NULL DEFAULT '1',
  20. `news_allow_ratings` tinyint(1) UNSIGNED NOT NULL DEFAULT '1',
  21. PRIMARY KEY (`news_id`),
  22. KEY `news_datestamp` (`news_datestamp`),
  23. KEY `news_reads` (`news_reads`)
  24. )

Wykonując zapytanie na bazie:
  1. 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.

  1. <?php
  2. ...
  3. if (!isset($_GET['readmore']) || !isnum($_GET['readmore'])) {
  4. $rows = dbcount("(news_id)", DB_NEWS, groupaccess('news_visibility')." AND (news_start='0'||news_start<=".time().") AND (news_end='0'||news_end>=".time().") AND news_draft='0'");
  5. if (!isset($_GET['rowstart']) || !isnum($_GET['rowstart'])) { $_GET['rowstart'] = 0; }
  6. if ($rows) {
  7. $result = dbquery(
  8. "SELECT tn.*, tc.*, user_id, user_name FROM ".DB_NEWS." tn
  9. LEFT JOIN ".DB_USERS." tu ON tn.news_name=tu.user_id
  10. LEFT JOIN ".DB_NEWS_CATS." tc ON tn.news_cat=tc.news_cat_id
  11. WHERE ".groupaccess('news_visibility')." AND (news_start='0'||news_start<=".time().") AND (news_end='0'||news_end>=".time().") AND news_draft='0'
  12. ORDER BY news_sticky DESC, news_datestamp DESC LIMIT ".$_GET['rowstart'].",$items_per_page"
  13. );
  14. $numrows = dbrows($result);
  15. if ($settings['news_style'] == "1") { $nrows = round((dbrows($result) - 1) / 2); }
  16. while ($data = dbarray($result)) {
  17. $news_cat_image = "";
  18. $news_subject = "<a name='news_".$data['news_id']."' id='news_".$data['news_id']."'></a>".stripslashes($data['news_subject']);
  19. if ($data['news_cat_image']) {
  20. $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>";
  21. } else {
  22. $news_cat_image = "";
  23. }
  24. $news_news = $data['news_breaks'] == "y" ? nl2br(stripslashes($data['news_news'])) : stripslashes($data['news_news']);
  25. if ($news_cat_image != "") $news_news = $news_cat_image.$news_news;
  26. $news_info = array(
  27. "news_id" => $data['news_id'],
  28. "user_id" => $data['user_id'],
  29. "user_name" => $data['user_name'],
  30. "news_date" => $data['news_datestamp'],
  31. "news_ext" => $data['news_extended'] ? "y" : "n",
  32. "news_reads" => $data['news_reads'],
  33. "news_comments" => dbcount("(comment_id)", DB_COMMENTS, "comment_type='N' AND comment_item_id='".$data['news_id']."'"),
  34. "news_allow_comments" => $data['news_allow_comments']
  35. );
  36. ...
  37. ?>


Może ktoś już robił taki skrypt - bardzo by mi to pomogło.