function printPostCode($user_id, $name, $surname, $description, $post_id, $sharing_date, $like, $likes, $img_url) { if ($img_url == "") { $img_url = "img/user.png"; } $data = new MysqlConnector(); $data->connectMysql(); #LOAD COMMENTS OF THE CURRENT POST $comments = $data->getComments($post_id); #CHECK IF THERE ARE COMMENTS AND PRINT THEM $num_of_comments = $comments->num_rows; if ($like) { $class_like = "glyphicon glyphicon-heart"; } else { $class_like = "glyphicon glyphicon-heart-empty"; } echo "\n <div class='row post-box' id=" . $post_id . ">\n <div class='col-lg-12 col-xs-12'>\n <div class='panel'>\n <div class='panel-heading'>\n <div class='row'>\n <div class='col-lg-1 col-xs-2 img-container'>\n <img class='img-rounded user-img' \n src='" . $img_url . "' >\n </div>\n <div class='col-lg-11 col-xs-10'>\n <strong class='author'>" . $surname . " " . $name . "</strong>\n <br> \n <span class='text-muted date'>\n posted on: " . $sharing_date . "</span>\n </div>\n </div>\n </div><!-- /panel-heading -->\n <div class='panel-body text'>\n <h3 class='text'>" . $description . "</h3>\n </div><!-- /panel-body -->\n <div class='panel-footer'>\n <button class='like'>\n <span class='" . $class_like . "'></span>\n <strong>\n <span class='like-num'>" . $likes . "</span> \n likes\n </strong>\n </button>\n \n <button class='comm'>\n <span class='glyphicon glyphicon-comment'></span>\n <strong>\n <span class='comm-num'>" . $num_of_comments . "</span>\n comments\n </strong>\n </button>\n \n <button class='reblog pull-right'>\n <span class='glyphicon glyphicon-plus'></span>\n </button>\n "; echo " \n <div class='write-comment'>\n <div class='panel-body'>\n <form class='comment-form' action='' method='post'>\n <textarea class='form-control elastic-box \n insert-comment' \n style='resize: none;' \n rows='2' name='comment' \n placeholder='Insert a comment...'></textarea>\n\n <button type='button' \n class='btn btn-default btn-xs comment-button pull-right' \n > <span class='glyphicon glyphicon-pencil'></span> Comment </button>\n </form>\n </div>\n </div>\n "; echo "<div class='all-comments'>"; if ($num_of_comments !== 0) { #PRINT COMMENTS OF THE POST while ($comment = $comments->fetch_assoc()) { printCommentCode($comment['user_id'], $comment['name'], $comment['surname'], $comment['description'], $comment['sharing_date'], $comment['img_url']); } } $data->disconnectMysql(); echo "</div>"; #close /all-comments echo "\n </div><!-- /panel-footer -->\n </div><!-- /panel -->\n "; echo " \n </div><!-- col-lg-5 col-xs-12 -->\n </div><!-- /row -->\n "; }
<?php include 'php_functions.php'; $data = new MysqlConnector(); $data->connectMysql(); $data->addPost(); $data->disconnectMysql();
FOREIGN KEY(followed_id) REFERENCES Users(user_id) ); ', 'CREATE TABLE Likes ( post_id INT UNSIGNED NOT NULL, user_id SMALLINT UNSIGNED NOT NULL, PRIMARY KEY(post_id, user_id), FOREIGN KEY(post_id) REFERENCES Posts(post_id), FOREIGN KEY(user_id) REFERENCES Users(user_id) ); '); return $creator[$n_statement]; } #####################Calls methods######################## #Create Mysql object $installer = new MysqlConnector(); #Connect to mysql $installer->connectMysql(); #Uninstall old tables for ($i = 0; $i < 5; $i++) { if ($installer->connection->query(deleteTables($i)) === TRUE) { echo "Deleted <br>"; } else { echo $installer->connection->error . '<br>'; } } #Install new tables for ($i = 0; $i < 5; $i++) { if ($installer->connection->query(addTables($i)) === TRUE) { echo "Created <br>"; } else { echo $installer->connection->error . '<br>'; }