We help IT Professionals succeed at work.
Get Started

How can I pull site views from my table from the last 30 days and display it in a specific format...

350 Views
Last Modified: 2021-04-21
Please see attached code for what I'm trying to do.

Thx,

Brian
<html>
<head>
</head>

<body>
<!--- Loop back 30 days from today --->
<cfloop index="d" from="1" to="30" step="1">
   
   <cfset myDate = "#dateFormat(dateAdd('d', -(d-1), now()), 'yyyy-mm-dd')#" >
   
   <!--- pull data from the "myDate" value  --->
   <cfquery name="getViews" datasource="#request.dsn#" username="#request.dsnUsername#" password="#request.dsnPassword#">
		SELECT days, views
        FROM site_views
        WHERE days = '#myDate#'  
   </cfquery>
   <!--- An example of a formatted input value for "days" : 2011-10-20 23:44:24 --->	   
</cfloop>

I'm trying to output my data into 2 separate lists. 

List 1: Days starting from beginning of 30 days ago.. = '2011/10/25', '2011/10/24', '2011/10/23',... '2011/11/06' (last 30 days worth)

List 2: The views and if there isn't any value for "days" meaning there were no views then it would = '0' but the overall list would be...
0, 1, 5, 6, 7.... 9 (last 30 days worth)    

</body>
</html>

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2015
Commented:
This problem has been solved!
Unlock 1 Answer and 27 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE