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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:13:18+00:00 2026-06-02T22:13:18+00:00

I hope you are all well. I am currently teaching myself PHP and as

  • 0

I hope you are all well.

I am currently teaching myself PHP and as part of this I have been attempting to develop a feedback system that stores the info off customer feedback cards for the restaurant where I work.

The problem that I have revolves around the php code that I am using to generate the json output that is then used by jqplot to create a graph.

Here is the code I am using to do this:

<?php

// $toDate and $fromDate will eventually be values coming over via post however i am using static values at the moment for testing

$toDate = time();
$fromDate = time() - (7 * 24 * 60 * 60);

$sql = "SELECT * FROM feedback WHERE visitDateTime BETWEEN FROM_UNIXTIME($fromDate) AND FROM_UNIXTIME($toDate)";

$result = mysql_query($sql) or die(mysql_error());
?>

After getting the data I then use this code in javascript and php to generate the jqplot data.

<script>
$(document).ready(function(){
 var line1 = [
<?php
while ($row = mysql_fetch_assoc($result)){
echo '[';
echo "'";
echo $row['visitDateTime'];
echo "',";
echo $row ['foodScore'];
echo ']';
echo ',';
}

?>

];

// code then goes on to generate the chart, etc....

</script>

This works fine and generates the following json output:

 var line1 = [
['2012-04-20 19:00:00',7],['2012-04-20 19:00:00',8],['2012-04-20 12:00:00',8],['2012-04-22 16:00:00',5],['2012-04-21 20:00:00',9],  

];

However, the problem that i have is that when 2 dates and times are the same, which they probably would be, then this causes problems on the chart because i have multiple values for 1 date.

After giving it some thought i came to the conclusion that what i need to actually be doing is calculating the average score for the dates and times so that it generates output like shown below:

var line1 = ['unique date/time', average of all scores from this date/time ]

But i have no idea how to even begin to do that.

I know this is probably wrong but im thinking that i need to loop through all the retrieved records and check to see if the date/time is the same. So basically, instead of returning this:

['2012-04-20 19:00:00',7],['2012-04-20 19:00:00',8],['2012-04-20 12:00:00',8],['2012-04-20 12:00:00',5],['2012-04-20 12:00:00',9]

I need to return this:

['2012-04-20 19:00:00',7.5],['2012-04-20 12:00:00',7.3]

If anyone could offer me any pointers on how to go about this it would really help me out.

Thanks everyone.

  • 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-02T22:13:21+00:00Added an answer on June 2, 2026 at 10:13 pm

    Instead of doing the averaging calculations on the server, you could let MySQL do it for you. You could use a query like this to retrieve the data grouped and averaged directly from MySQL

    SELECT avg(foodScore), visitDateTime FROM feedback WHERE visitDateTime BETWEEN FROM_UNIXTIME($fromDate) AND FROM_UNIXTIME($toDate) group by visitDateTime
    

    Let me know if this doesn’t work

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

Sidebar

Related Questions

hope all is well. I am using Version 7.0. This morning I was struggling
Hi friends hope all r doing well. I have a problem while reading xml
I currently have 2 pages: Follow.php :a PHP page which is all setup with
I currently have a table with all the data, using this data i want
hope all is swell! I was hoping I had cracked this problem but it
I'm not a a very experienced Windows developer, so I hope this all makes
Currently I am working with a commercial project with PHP. I think this question
I have been searching for an answer to this question for days and it
(First of all I don't speak english as well as I wish, I hope
I hope the title is chosen well enough to ask this question. Feel free

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.