IFD:WebAdvancedII/Carlo Enke: Difference between revisions

From Medien Wiki
Line 24: Line 24:
<pre>
<pre>
<?php
<?php
  $sql = "
  (
  SELECT
    news.news_id AS id,
    news.news_title AS title,
    LEFT(news.news_body, 100) AS body,
    news.time AS time,
    'news' AS `type`
  FROM
    news
  )
  UNION ALL
  (
  SELECT
    posts.post_id AS id,
    posts.post_title AS title,
    LEFT(posts.post_body, 300) AS body,
    posts.time AS time,
    'posts' AS `type`
  FROM
    posts
  )
  UNION ALL
  (
  SELECT
    albums.album_id AS id,
    albums.album_title AS title,
    LEFT(albums.album_body, 200) AS body,
    albums.time AS time,
    'albums' AS `type`
  FROM
    albums
  )
  ORDER BY
    time desc
  ";


$sql = "
$qry = mysql_query($sql);
(
while( $row = mysql_fetch_object($qry) )
SELECT
{
news.news_id AS id,
if($row->type == "posts"){
news.news_title AS title,
echo "<div class='index_post'><div class='ip_img'><img src='admin/core/post_image/default.jpg' width='100px'></div><div class='post'><a href='blog_read.php?pid=" . $row->id . "'><h1>" . utf8_encode($row->title) . "</h1></a>" . utf8_encode($row->body) . "<hr/><font size='1' color='#aaa'>Blogeintrag vom " . date("d.m.Y", $row->time) . "</font></div></div>";
LEFT(news.news_body, 100) AS body,
}else if($row->type == "news"){
news.time AS time,
echo "<div class='news'><h1>" . utf8_encode($row->title) . "</h1>" . utf8_encode($row->body) . "<hr/><font size='1' color='#aaa'>" . date("d.m.Y", $row->time) . "</font></div>";
'news' AS `type`
}else if($row->type == "albums"){
FROM
echo "<div class='news'><a href='view_album.php?album_id=" . $row->id . "'><h1>" . utf8_encode($row->title) . "</h1></a>" . utf8_encode($row->body) . "<br/><br/><div class='index_album'></div><div class='index_album'></div><div class='index_album'></div><div class='index_album'></div><div class='index_album'></div><div class='index_album'></div><br/><br/><br/><br/><br/><hr/><font size='1' color='#aaa'>erstellt am " . date("d.m.Y", $row->time) . "</font></div>";
news
}
)
}
UNION ALL
(
SELECT
posts.post_id AS id,
posts.post_title AS title,
LEFT(posts.post_body, 300) AS body,
posts.time AS time,
'posts' AS `type`
FROM
posts
)
UNION ALL
(
SELECT
albums.album_id AS id,
albums.album_title AS title,
LEFT(albums.album_body, 200) AS body,
albums.time AS time,
'albums' AS `type`
FROM
albums
)
 
ORDER BY
time desc
";
$qry = mysql_query($sql);
while( $row = mysql_fetch_object($qry) )
{
if($row->type == "posts"){
echo "<div class='index_post'><div class='ip_img'><img src='admin/core/post_image/default.jpg' width='100px'></div><div class='post'><a href='blog_read.php?pid=" . $row->id . "'><h1>" . utf8_encode($row->title) . "</h1></a>" . utf8_encode($row->body) . "<hr/><font size='1' color='#aaa'>Blogeintrag vom " . date("d.m.Y", $row->time) . "</font></div></div>";
}else if($row->type == "news"){
echo "<div class='news'><h1>" . utf8_encode($row->title) . "</h1>" . utf8_encode($row->body) . "<hr/><font size='1' color='#aaa'>" . date("d.m.Y", $row->time) . "</font></div>";
}else if($row->type == "albums"){
echo "<div class='news'><a href='view_album.php?album_id=" . $row->id . "'><h1>" . utf8_encode($row->title) . "</h1></a>" . utf8_encode($row->body) . "<br/><br/><div class='index_album'></div><div class='index_album'></div><div class='index_album'></div><div class='index_album'></div><div class='index_album'></div><div class='index_album'></div><br/><br/><br/><br/><br/><hr/><font size='1' color='#aaa'>erstellt am " . date("d.m.Y", $row->time) . "</font></div>";
}
}
?>
</pre>
</pre>
aufgerufen und nach Datum des Eintrages sortiert.
aufgerufen und nach Datum des Eintrages sortiert.