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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:26:04+00:00 2026-05-16T08:26:04+00:00

I’m dabbling with pChart and would like to start with a simple line graph

  • 0

I’m dabbling with pChart and would like to start with a simple line graph showing the growth in membership over time.

Y-axis would be # of members
X-axis would be time

For each time datapoint, I need a corresponding total members datapoint.

My user table is structured as:
[user_id] [join_date]

The approach I came up with on the bus to work this morning is:

$Q = " SELECT MONTH(join_date), DAY(join_date), COUNT(user_id)"
   . " FROM user_basic_data GROUP BY join_date";
$R = mysql_query($Q);

$dateS = '';
$totalS = '';
$c = 0; // total members counter
while ($row = mysql_fetch_row($R)) {
    $dateS .= $row[0].'-'.$row[1].','; // month-day,month-day,month-day
    $c = $row[2] + $c; // new total for new date
    $totalS .= $c.','; // total1,total2,total3
}
// trim trailing commas
$dateS = substr($dateS, 0, -1);
$totalS = substr($totalS, 0, -1);

echo "<p>$dateS</p>"; // Ex: 8-10,8-15,8-20
echo "<p>$totalS</p>"; // Ex: 12,17,23

Those string formats are how pChart likes the data, and I know the current query would need a year value as well for real use, so please don’t get hung up on those points.

I’d like to know if there’s a better way to go about getting the changing total members over time. I’m guessing handling it within MySQL would be faster, but I can’t think of a way to do that.

Thank you for your time.

  • 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-16T08:26:05+00:00Added an answer on May 16, 2026 at 8:26 am

    To get a running total, use:

    SELECT DISTINCT
           DATE(ubd.join_date) AS dt, 
           (SELECT COUNT(*)
              FROM user_basic_data t
             WHERE DATE(t.join_date) <= DATE(ubd.join_date)) AS num_users
      FROM user_basic_data ubd 
    

    DATE returns dates as YYYY-MM-DD; If you still want Month-Day – use DATE_FORMAT by replacing the DATE(udb.join_date) with:

    DATE_FORMAT(ubd.join_date), '%m-%d')
    

    You don’t need the logic to create the comma separated lists in PHP – just need to populate the two variables:

    $Q = " SELECT GROUP_CONCAT(x.dt) AS dates,
                  GROUP_CONCAT(x.num_users) AS totals
             FROM (SELECT DISTINCT
                          DATE(ubd.join_date) AS dt, 
                          (SELECT COUNT(*)
                             FROM user_basic_data t
                            WHERE DATE(t.join_date) <= DATE(ubd.join_date)) AS num_users
                     FROM user_basic_data ubd ) x";
    $R = mysql_query($Q);
    
    while ($row = mysql_fetch_row($R)) {
       echo "<p>$row[0]</p>"; // Ex: 8-10,8-15,8-20
       echo "<p>$row[1]</p>"; // Ex: 12,17,23
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.