Code

<?php
include ‘functions.php’;
require_once ‘core/db.php’;

if(isset($_GET[‘cat’])){
$cat = $_GET[‘cat’];
}else{
$cat = ‘all’;
}
$user_id = $_SESSION[‘user_id’];

get_header(); ?>
<style>
#comments_feed_holder
{
display:none;
}
</style>
<div class=”imagewrap”>

<?php

if ($cat == ‘most_popular’) {

$statement = $db->prepare(“SELECT id, movie_title, movie_description, movie_url, movie_actors, movie_thumbnail, time_uploaded, movie_categories FROM movies WHERE movie_status=1 AND comment_count IS NOT NULL ORDER BY comment_count DESC”);
$statement->execute();
$statement->bind_result($movie_id, $movie_title, $movie_description, $movie_url, $movie_actors, $movie_thumbnail, $time_uploaded, $movie_categories);
$statement->store_result();
$count = $statement->num_rows;

} else if($cat != ‘all’){

$statement = $db->prepare(“SELECT id, movie_title, movie_description, movie_url, movie_actors, movie_thumbnail, time_uploaded, movie_categories FROM movies WHERE movie_status=1 AND movie_categories=? ORDER BY id DESC”);
$statement->bind_param(‘s’, $cat);
$statement->execute();
$statement->bind_result($movie_id, $movie_title, $movie_description, $movie_url, $movie_actors, $movie_thumbnail, $time_uploaded, $movie_categories);
$statement->store_result();
$count = $statement->num_rows;

}else{

$statement = $db->prepare(“SELECT m.id, m.movie_title, m.movie_description, m.movie_url, m.movie_actors, m.movie_thumbnail, m.time_uploaded, m.movie_categories FROM movie_comments mc LEFT JOIN movies m ON mc.movies_id = m.id WHERE m.movie_status=1 GROUP BY m.id, m.movie_title, m.movie_description, m.movie_url, m.movie_actors, m.movie_thumbnail, m.time_uploaded, m.movie_categories ORDER BY MAX(mc.time_posted) DESC”);
$statement->execute();
$statement->bind_result($movie_id, $movie_title, $movie_description, $movie_url, $movie_actors, $movie_thumbnail, $time_uploaded, $movie_categories);
$statement->store_result();
$count = $statement->num_rows;

}
?>

<?php while($statement->fetch()){

$movie_blurb = substr($movie_description,0,130);
$movie_thumbnail_explode = explode(“, “, $movie_thumbnail);
$movie_thumbnail_count = count($movie_thumbnail_explode);
if($movie_thumbnail_count>1){
$movie_thumbnail = $movie_thumbnail_explode[rand(0, ($movie_thumbnail_count-1))];
}
$path = ‘/movie.php?id=’.$movie_id.”;

?>
<div class=”shot” id=”<?php echo $movie_id; ?>”>
<div class=”shotwrapper”>
<a href=”<?php echo home_url(‘home_url’).$path;?>”>
<div class=”shotinner”>
<img class=”imagehome” src=”<?php echo home_url(‘movie_images’).$movie_thumbnail; ?>” />
<div class=”shothover”>
<?php
//Get comments
$comments = $db->prepare(“SELECT movie_comments.id, movie_comments.comment, movie_comments.movies_id, movie_comments.user_id, movie_comments.time_posted, users.profile_picture, users.first_name, users.last_name FROM movie_comments LEFT JOIN users ON movie_comments.user_id = users.id WHERE movie_comments.movies_id=? ORDER BY movie_comments.time_posted DESC LIMIT 1″);
$comments->bind_param(‘i’, $movie_id);
$comments->execute();
$comments->bind_result($comment_id,$comment, $comments_movie_id, $comment_userid, $comment_time_posted, $comments_profile_picture, $comments_firt_name, $comments_last_name);
$comments->store_result();
$comment_count = $comments->num_rows; ?>
<?php
if($comment_count>0){
while($comments->fetch()){ ?>
<?php if($cat == ‘all’ || $cat ==’most_popular’){?>

<div class=”commentPic” style=”margin:0 auto; width:100%; text-align:center; margin-top:10px;”>
<img src=”<?php echo home_url(‘profile_picture’); ?><?php echo $comments_profile_picture;?>” width=”40″ height=”40″>

</div>
<div class=”text” style=”text-align:center; width:100%; font-size:14px; font-weight:bold;”>
<p style=”color:#FFFFFF; font-weight:normal;”><span style=”color:#38A7AE; font-weight:bold;”><?php if($comment_userid == $user_id){ echo “You<br/>”; }else{ echo ucwords($comments_firt_name); echo ‘&nbsp’; echo ucwords($comments_last_name);echo ‘<br/>’;} ?></span> <?php echo substr($comment,0,200); ?></p>
</div>
<?php if($comment_userid != $user_id){ ?>
<?php if(user_is_logged_in()){ ?>

<div id=”repost_comment”>
<a href=”#” class=”repost_comment_link” id=”<?php echo $comment_id; ?>”><span class=”<?php echo $movie_id; ?>”>Repost</span></a>
</div>
<?php } ?>
<?php } ?>

<?php }}
}
else
{
?>
<h1><?php echo $movie_title; ?></h1>
<h3><?php echo $movie_blurb; ?></h3>
<?php } ?>
<?php $comments->free_result(); ?>
</div>
</div>
</a>
<div class=”shotbottom”>

<h3><?php echo $movie_title; ?>
<a href=”<?php echo home_url(‘home_url’); ?><?php echo $path; ?>” class=”plus”></a>
<a href=”#” class=”share_btn heart” id=”<?php echo $movie_id; ?>”></a>
</h3>
<div class=’heartnotlikedindex’></div>
</div>
</div>
</div>

<?php
//Get comments
$comments = $db->prepare(“SELECT movie_comments.id, movie_comments.comment, movie_comments.movies_id, movie_comments.user_id, movie_comments.time_posted, users.profile_picture, users.first_name, users.last_name FROM movie_comments LEFT JOIN users ON movie_comments.user_id = users.id WHERE movie_comments.movies_id=? ORDER BY movie_comments.time_posted DESC LIMIT 1″);
$comments->bind_param(‘i’, $movie_id);
$comments->execute();
$comments->bind_result($comment_id,$comment, $comments_movie_id, $comment_userid, $comment_time_posted, $comments_profile_picture, $comments_firt_name, $comments_last_name);
$comments->store_result();
$comment_count = $comments->num_rows; ?>
<ul id=”comments_feed_holder”>
<?php
if($comment_count>0){
while($comments->fetch()){ ?>
<?php if($cat == ‘all’ || $cat ==’most_popular’){?>
<li>
<div class=”commentPic”>
<img src=”<?php echo home_url(‘profile_picture’); ?><?php echo $comments_profile_picture;?>” width=”40″ height=”40″>
<div class=”commentOverlay”>
<img src=”<?php echo home_url(‘images’);?>comment_overlay_white.png” width=”40″ height=”40″>
</div>
</div>
<div class=”text”>
<p><span><?php if($comment_userid == $user_id){ echo “You: “; }else{ echo ucwords($comments_firt_name); echo ‘&nbsp’; echo ucwords($comments_last_name);echo ‘&#58’;} ?></span> <?php echo $comment; ?></p>
</div>
<?php if($comment_userid != $user_id){ ?>
<?php if(user_is_logged_in()){ ?>

<div id=”repost_comment”>
<a href=”#” class=”repost_comment_link” id=”<?php echo $comment_id; ?>”><span class=”<?php echo $movie_id; ?>”>Repost</span></a>
</div>
<?php } ?>
<?php } ?>
<div class=”clearfix”></div>
</li>
<?php }} }?>
</ul>
<?php $comments->free_result(); ?>

 

<?php } $db->close(); ?>

<?php if($count == 0){ ?>
<li>There are no movies to display</li>
<?php } ?>

</ul>

 
<div class=”clearfix”></div>
</div>

<script type=”text/javascript” src=”ajax/js/repost_comment.js”></script>

 
<?php get_footer(); ?>

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s