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 8075475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:59:48+00:00 2026-06-05T14:59:48+00:00

I have a classified site… I’m trying to make a sql query that COUNTS

  • 0

I have a classified site… I’m trying to make a sql query that COUNTS the number of ads the user has posted in last 7 days, but I have a problem…

I’m trying to show in user profile something like this for example: [Username] has posted 30 ads in last 7 days

Here is my sql query ->

SELECT COUNT(*) 
FROM table_name 
WHERE user_id = '[user_id]' AND created_date > NOW() - INTERVAL 7 DAY

So in my case “table_name” contains ALL the ads from all the users and by “user_id = ‘[user_id]'” I show the user A his number of ads, and to USER B his number of ads etc…

So this query works, it counts the number of ads correctly, BUT, if for example user enters on site and DELETE’s 1,2 or whatever number of his ads, this number will be “minused” from the “[Username] has posted 30 ads in last 7 days”

  1. So let’s say for example user posted 20 ads in the last 5 days – The correct result is [Username] has posted 20 ads in last 7 days
  2. Now user enters on site and delete’s 4 ads – Now the result is [Username] has posted 16 ads in last 7 days

Can somebody help me please, what can I add to the query so the count still shows the correct number of ads (in my case 20 ads), even if the ads where deleted..

Thank you
Cheers

  • 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-06-05T14:59:50+00:00Added an answer on June 5, 2026 at 2:59 pm

    Instead of deleting a row using a DELETE ... WHERE ... statement, add a deleted column and use an UPDATE statement:

    UPDATE ... SET deleted = 1 WHERE ...
    

    Then your counting function will work without modification.

    Of course you will now have to fix all the rest of your code to not show deleted adverts. You can do this by adding WHERE NOT deleted to all your other queries. You could also create a view that only shows ads that are not deleted and update your code to query this view instead of the original table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have an app that has listings - think classified ads - and each listing
I have this: $query=DELETE FROM classified, $sql_table WHERE classified.ad_id = '$id' AND classified.classified_id =
I have a wordpress based classifieds site, i am trying to create and xml
I have a table categories that has: id, name, subcategory_id, parent_id . Another table
I'm programming a website that allows users to post classified ads with detailed fields
I have a program that classifies text and would like to make it interactive
Morning All, I have classified ads with various categories and sub categories and I
I have a database full of classified adverts for computers for sale that have
I have a number of files that I checked into SVN without having set
I have a good LINQ query that is working well, it returns a result

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.