6 Replies - 252 Views - Last Post: 22 April 2013 - 04:37 PM Rate Topic: -----

#1 olimoli123  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 01-February 09

Graphing or statistics like program

Posted 22 April 2013 - 03:53 PM

Hello, i'm looking to create a graph which will show every day of the current week and how many users have accessed the page on that day.

For example

Monday - 1 views.
Tuesday - 2 views. etc

How would i graph this data when retrieving it from the database?

Sorry if this isnt in the right section, i wasn't sure where to place this topic.

Thanks,

Oliver
Is This A Good Question/Topic? 0
  • +

Replies To: Graphing or statistics like program

#2 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3480
  • View blog
  • Posts: 11,867
  • Joined: 12-December 12

Re: Graphing or statistics like program

Posted 22 April 2013 - 04:01 PM

Searching "php graph" comes up with a number of plug-in options that you could investigate. For example, JpGraph.

It is also possible to embed the data in the page and let Javascript build the graph.

This post has been edited by andrewsw: 22 April 2013 - 04:03 PM

Was This Post Helpful? 0
  • +
  • -

#3 olimoli123  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 01-February 09

Re: Graphing or statistics like program

Posted 22 April 2013 - 04:06 PM

Fantastic thanks!
But one thing i don't understand is how i would plot every day of the year and so it updates to the current week.
Was This Post Helpful? 0
  • +
  • -

#4 BenignDesign  Icon User is offline

  • holy shitin shishkebobs
  • member icon




Reputation: 6095
  • View blog
  • Posts: 10,531
  • Joined: 28-September 07

Re: Graphing or statistics like program

Posted 22 April 2013 - 04:15 PM

If the data is stored in the database, you need to write your code to pull from this date last year to this date this year.

$this_year=date('Y');
$last_year=$this_year-1;



Something along those lines...
Was This Post Helpful? 1
  • +
  • -

#5 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3480
  • View blog
  • Posts: 11,867
  • Joined: 12-December 12

Re: Graphing or statistics like program

Posted 22 April 2013 - 04:30 PM

IN the SQL statement that retrieves the data you could use an expression to obtain data for the last year. In MySql you could use CURDATE() in combination with DATE_ADD(). Something like:

field_name >= DATE_ADD(CURDATE(), INTERVAL '-1' YEAR)

the docs
But, of course, you'll need to group the data (unless it is already grouped) and you'll end up with 300+ columns :) if you do this per day.

This post has been edited by andrewsw: 22 April 2013 - 04:34 PM

Was This Post Helpful? 1
  • +
  • -

#6 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,990
  • Joined: 08-June 10

Re: Graphing or statistics like program

Posted 22 April 2013 - 04:31 PM

If it's a SQL database, you'd be better of doing that in the SQL query. For example, in MySQL, you might do:
SELECT stuff FROM theTable
WHERE theDate >= NOW() - INTERVAL 1 YEAR


In MSSQL you could do the same like:
SELECT stuff FROM theTable
WHERE theDate >= DATEADD(YEAR, -1, GETDATE());


Was This Post Helpful? 2
  • +
  • -

#7 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3480
  • View blog
  • Posts: 11,867
  • Joined: 12-December 12

Re: Graphing or statistics like program

Posted 22 April 2013 - 04:37 PM

Atli 's MySql expression is neater :) using date arithmetic.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1