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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:27:30+00:00 2026-05-14T04:27:30+00:00

I have a system I am trying to design that will retrieve information from

  • 0

I have a system I am trying to design that will retrieve information from a database, so that it can be plotted in a jquery graph. I need to retrieve the information and somehow put it in the necessary coordinates format (for example two coordinates var d = [[1269417600000, 10],[1269504000000, 15]];).

My table that I am selecting from is a table that stores user votes with fields:

points_id (1=vote up, 2=vote down),
user_id,
timestamp, (UNIX TIMESTAMP)
topic_id

What I need to do is select all the votes and somehow group them into respective days and then sum the difference between 1 votes and 2 votes for each day. I then need to somehow display the data in the appropriate plotting format shown earlier. For example April 1, 4 votes. The data needs to be separated by commas, except the last plot entry, so I am not sure how to approach that. I showed an example below of the kind of thing I need but it is not correct,

echo "var d=[";
$query=mysql_query(
    "SELECT *, SUM(IF(points_id = \"1\", 1,0))-SUM(IF([points_id = \"2\", 1,0)) AS 'total'
    FROM points LEFT JOIN topic ON topic.topic_id=points.topic_id
    WHERE topic.creator='$user' GROUP by timestamp
    HAVING certain time interval"
);
while ($row=mysql_fetch_assoc($query)){
    $timestamp=$row['timestamp'];
    $votes=$row['total'];
    echo "[$timestamp,$vote],";
}
echo "];";
  • 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-14T04:27:31+00:00Added an answer on May 14, 2026 at 4:27 am

    It would certainly be a lot saner to just use -1 as a downvote. Then you can simply run SUM(points_id)

    To generate javascript-friendly notation, you can use good old mate json_encode.

    $sql = "SELECT `timestamp`, SUM(points_id) FROM ..."; // yadda yadda
    $result = mysql_query($sql);
    
    $out = array();
    while ($row = mysql_fetch_assoc($result)) {
        $out[] = array((int) $row['timestamp'], (int) $row['total']);
    }
    echo "d = " . json_encode($out) . ";\n";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a legacy database with a pretty evil design that I need to
I have two system calls GetSystemTime() and GetThreadTimes() that I need to calculate the
Using PHP and MySQL, I have a forum system I'm trying to build. What
I'm going nuts here, trying to get my system configured. I have a laptop
I have a system that combines the best and worst of Java and PHP.
I have a system that uses a meta refresh to a logout page, which
We have a system where customers, mainly European enter texts (in UTF-8) that has
I'm trying to fix a design flaw that I recently ran across in some
I'm trying to weigh the pros and cons of a database design, and would
To promote bonding in my fraternity, I'm trying to design a system where people

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.