<!DOCTYPE html>
<html lang="en">
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>

<?php

if (isset($_GET['id'])) {
    $id = $_GET['id'];
}

if (!empty($_POST["id"])){

// Include the database configuration file
// Database configuration
 $dbHost     = "localhost";
                        $dbUsername = "creatcok_rdi";
                        $dbPassword = "ci/05041/2013";
                        $dbName     = "creatcok_woman";


// Create database connection
$db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);

// Check connection
if ($db->connect_error) {
    die("Connection failed: " . $db->connect_error);
}

// Count all records except already displayed
$query = $db->query("SELECT COUNT(*) as num_rows FROM tbl_articles WHERE id < " . $_POST['id'] . " ORDER BY id DESC");
$row = $query->fetch_assoc();
$totalRowCount = $row['num_rows'];

$showLimit = 3;

// Get records from the database
$query = $db->query("SELECT * FROM tbl_articles WHERE id < " . $_POST['id'] . " ORDER BY id DESC LIMIT $showLimit");

if ($query->num_rows > 0){
while ($article = $query->fetch_assoc()) {
    $postID = $article['id'];
    ?>



    <div class="col-12 mt-5 mb-5">
        <div class="card p-4 border-0">
            <a href="article.php?id=<?php echo $article['id']; ?>"
               style="text-decoration: none; font-family: 'Roboto', sans-serif!important; color: #000;">
                <div class="titles py-4"><?php echo $article['title']; ?></div>
            </a>


            <style>

                .entry-header .entry-meta {
                    border-top: 1px solid #ddd;
                }

                .entry-meta {
                    font-size: 10px;
                    letter-spacing: 2px;
                    text-transform: uppercase;
                    font-family: 'Roboto', sans-serif!important;
                    color: #6f6b6b;
                    text-align: center;
                }
            </style>


            <div class="entry-meta" style="margin-bottom: 10px!important;">
			<span class="date-bar-white-bg">

				<span class="entry-cat">By <?php echo $article['author']; ?></a></span>

									<span class="entry-date updated"> | <time datetime="2019-03" itemprop="datePublished">

									     <?php $timeStamp = date("F d, Y", strtotime($article['created_at']));
                                         echo $timeStamp; ?>
									   </time>
									   </span>
			</span>
            </div>

            <a href="article.php?id=<?php echo $article['id']; ?>">
                <img src="assets/img/post_pic/<?php echo $article['image']; ?>"
                     class="card-img-top" style="width: 100%!important; height: 100% !important;"
                     id="image"
                     alt="...">
            </a>
            <div class="card-body">
                <a href="article.php?id=<?php echo $article['id']; ?>"
                   style="text-decoration: none; font-family: 'Roboto', sans-serif!important; color: #6f6b6b; font-size: 14px">
                    <p class="card-text">
                        <?php
                        echo $article['summary']; ?>
                    </p>
                </a>
                <a href="article.php?id=<?php echo $article['id']; ?>" class="btn btn-dark mt-3">Read
                    More</a>
            </div>
        </div>
    </div>

<?php } ?>
<?php if ($totalRowCount > $showLimit) { ?>
    <div class="show_more_main" id="show_more_main<?php echo $postID; ?>">
        <span id="<?php echo $postID; ?>" class="show_more" title="Load more posts" style="font-family: AngleciaPro-Md">Show more</span>
        <span class="loding" style="display: none;"><span class="loding_txt">Loading...</span></span>
    </div>
<?php } ?>
<?php
}
}
?>