Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

showing an article based on date it was published

<?php
  // Fetching all the Navbar Data
  require('./includes/nav.inc.php');

  $current_date = date("Y-m-d");
  error_reporting(0);
?>

<!-- Article List Container -->
<section class="py-1 category-list">
  <div class="container">
    <h2 class="headings">Artikel
      <?php
      echo "<h2> $current_date </h2>"
      ?>
    </h2>
    <div class="card-container">
      <?php

        // Article Query to fetch maximum 5 random articles
        $articleQuery = " SELECT category.category_name, category.category_color, article.*
                          FROM category, article
                          WHERE article.category_id = category.category_id
                          AND article.article_date <= {$current_date}
                          AND article.article_active = 1
                          ORDER BY RAND() LIMIT 5";
        // Running Article Query 
        $result = mysqli_query($con,$articleQuery);

        // Row stores the no of rows in the return data from Query
        $row = mysqli_num_rows($result);
        

        // If query has any result (records) => If any articles are present
        if($row > 0) {
          
          // Fetching the data of particular record as an Associative Array
          while($data = mysqli_fetch_assoc($result)) {
            
            // Storing the article data in variables
            $category_color = $data['category_color'];
            $category_name = $data['category_name'];
            $category_id = $data['category_id'];
            $article_id = $data['article_id'];
            $article_title = $data['article_title'];
            $article_image = $data['article_image'];
            $article_desc = $data['article_description'];
            $article_date = $data['article_date'];

i want my news portal to only appear for a given date and not show up before that date. like a scheduled article. so he can display past or current news. in this screenshot, that article was supposed to be published on august 3rd 2023.

is there a mistake with my sql query? any suggestion? enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

date is a text field so needs to be quoted … <= \"{$current_date}\"

This gets all posts before or on the current date. Not sure if this was your intention.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading