function getPosts($descriptor = '') { $where_clause = "WHERE blog_posts.descriptor = '{$descriptor}'"; if ($descriptor == '') { $where_clause = ''; } $result = mysql_query("\n SELECT blog_posts.descriptor, blog_posts.title, blog_posts.content, blog_posts.poster,\n UNIX_TIMESTAMP(blog_posts.posted_date) as posted_date, \n COUNT(blog_comments.`comment-id`) as num_comments \n FROM blog_posts LEFT OUTER JOIN blog_comments on blog_posts.descriptor = blog_comments.descriptor \n {$where_clause}\n GROUP BY blog_posts.descriptor \n ORDER BY posted_date DESC\n ") or die(mysql_error()); while ($row = mysql_fetch_array($result)) { displayPost($row['descriptor'], $row['title'], $row['content'], $row['poster'], $row['posted_date'], $row['num_comments']); } }
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.0/css/materialize.min.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.0/js/materialize.min.js"></script> </head> <body> <h1 class="heading"><?php print $config['title']; ?> </h1> <div class="contentstuff"> <?php //display post at index function displayPost($index) { global $posts; global $config; print "\n\t\t\t\t\t\t<div class='card'>\n\t\t\t\t\t\t\t<div class='cardcontent'>\n\t\t\t\t\t\t\t\t<h4>" . $posts['posts'][$index]['title'] . "</h4>\n\t\t\t\t\t\t\t\t<p>" . $posts['posts'][$index]['content'] . "</p>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t<div class='cardfooter'>\n\t\t\t\t\t\t\t\t<div class='minilogo'><img src='" . $config['logo'] . "'></div>\n\t\t\t\t\t\t\t\t<div class='cardinfo'>" . $config['name'] . "<br>" . $posts['posts'][$index]['date'] . "</div>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t"; } for ($i = count($posts['posts']) - 1; $i >= 0; $i--) { displayPost($i); } ?> </div> <footer> <div class="container"> <span class="grey-text">Made by qwertxzy. CSS made by Noahz.</span> </div> </footer> </body> </html>
<?php require_once "functions.php"; if (isset($_GET['id'])) { $id = $_GET['id']; $post = getPost($id)->fetchObject(); displayPost($post); } function displayPost($post) { ?> <h3><?php echo $post->title; ?> </h3> <p><?php echo $post->content; ?> </p> <?php }