Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7541229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:50:22+00:00 2026-05-30T07:50:22+00:00

i have 2 tables for categories & posts the categories table contain id name

  • 0

i have 2 tables for categories & posts

the categories table contain

id
name

and the posts table contain

id
name
post
added_date

the date stored like (2010-09-05).

when i print the categories by this code

$query=mysql_query("select id,name from categories order by id");
while($row=mysql_fetch_assoc($query)){

echo "$row[id] : $row[name] <br />";
}

i need to print word ( new ) next to the category that have any new post for 3 days only after three days it should be normal category name without word (NEW).

regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T07:50:23+00:00Added an answer on May 30, 2026 at 7:50 am

    You need to change your query to report the newest posting date for each category. The simplest way to do this is with an aggregate function in the query:

    $query = mysql_query("select c.id, c.name, MAX(p.added_date) AS last_date from categories c inner join posts p on p.category_id = c.id group by c.id order by c.id"); 
    

    Then, when printing the list of categories, if the value of the last_date column is newer than 4 days old, print the (new) text. For example:

    while( $row = mysql_fetch_assoc($query) )
    {     
        $id = $row['id'];
        $name = $row['name'];
    
        echo( "$id : $name " );
    
        $daysOld = ( time() - strtotime( $row['last_date'] ) ) / 86400; 
        if( $daysOld < 4 ) 
            echo( "(new)" ); 
    
        echo( "<br />" );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables namely 'categories' & 'products' as follows: categories id | name
I have two table posts & categories post_id | post_title | post_content | post_cat
I have three tables: videos, videos_categories, and categories. The tables look like this: videos:
I have 3 tables in my DB (MySQL). categories (name:string) items (name:string, category_id:int) votes
Say I have two tables I want to join. Categories: id name ---------- 1
I have a table named categories, which contains ID(long), Name(varchar(50)), parentID(long), and shownByDefault(boolean) columns.
i have a main table categories like this categories_id | categories_status | parent_id 1
I have 2 tables .. categories & deals. Ultimately, I want to do the
I have the following tables: 1-Categories: -CategoryID -CategoryName -ParentID 2-Items: -ItemId -ItemName -CategoryID categories
I have two tables, movies and categories , and I want to get an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.