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

  • Home
  • SEARCH
  • 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 3760332
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:27:19+00:00 2026-05-19T10:27:19+00:00

I am trying to create graph for the number of posts by a user

  • 0

I am trying to create graph for the number of posts by a user in last 6 months using Google Charts API.
My table structure is like this –

-> Userid - varchar(20)
-> Post_year - varchar(4)
-> Post_month - varchar(2)

To get the number of posts in last 6 months by a user, I have my query like this…

SELECT COUNT(*) AS count, `Post_year`, `Post_month`
FROM (`table`)
WHERE `Userid` = '1234'
AND `Post_year` >= '$year_offset'
AND `Post_month` >= '$month_offset'
GROUP BY `Post_year`, `Post_month` 

As you can see, I am storing just the post year and month, and then using an offset variable to get the posts. This works like…

Case 1: if current year and month are 2010/12, then offset ones are 2010/7
Case 2: if current year and month are 2011/1, then offset ones are 2010/8

Now the query in Case 1 works fine as it is supposed to.

// Get all posts by a user
// ...
WHERE Post_year >= 2010
AND Post_month >= 7

But in case of Case 2, it doesn’t. Since the last part of query becomes…

// Get all posts by a user
// ...
WHERE Post_year >= 2010
AND Post_month >= 8

Hence, the posts of 2010/1 do not satisfy the condition Post_month >= 8.

How should I change my query for it to work in Case 2 as well.

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-19T10:27:20+00:00Added an answer on May 19, 2026 at 10:27 am

    You could do something like

    AND `Post_year` * 100 + `Post_month` >= $year_offset * 100 + $month_offset
    

    But proper way is to introduce Post_date field and use it in query.

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

Sidebar

Related Questions

I'm trying to create a horizontal 100% stacked bar graph using HTML and CSS.
Trying to create a user account in a test. But getting a Object reference
Trying to create several layers of folders at once C:\pie\applepie\recipies\ without using several different
I'm trying to create a sitemap using Linq to Xml, but am getting an
I am currently trying to create graph statistics for jobs in a PBS. I
I am using a JS object to create graphs with Google visualization. I am
I'm trying to prepare data for a graph using LINQ. The problem that i
So I'm trying to use the new batches functionality to the graph API, which
I'm trying to post to a facebook wall, without using an API such as
Facebook has a new Batch request Graph API that I'm trying to consume. The

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.