# Extract data

What would be the equation form to pull out the results for a field for the last 7 days?
let’s say i would like to know what amount of data a user took over that period. The table field in the users table is known as downloaded for obvious reasons.
ive tried the current format

Well, you can sum something and then use the date to divide by. Makes no sense at all.

How does your table keep track of downloads? Normally, you would have a table that tracks what the user downloaded, the date/time it was downloaded and the user_id to know who downloaded it. Then, you can do reports based on date and get totals with a simple query. If you want to just keep the running total for a week, you would need to keep the total for each day and then sum all the days. Once a new day comes along, the 7 day total would be accurate back to 7 days. Either way would work.

Not sure if that helps, but, hope so…

I dont have what you said. My downloaded field is int format.
The equation i’ve did in the SUM is the equation i already have in php to show that, and it works and i’m trying to recreate it for mysql so i can sort a table by daily, 7 days and 1 month downloaded

Mariusd, You can SUM a total of any field. But, if the data is just an integer (INT) it is just a number.
This means you can sum it all you want to get totals. BUT, again, if you want to use dates I showed you
how to use that in the WHERE clause. BUT, again, you need a DATE field to compare against.

You did not show us your table structure, so we have no idea what is in the table you want to run queries
that I gave you and just adjust it for 1 day, 7 day, 1 month and it will work. But, you need to explain the
way you store the date for each download and the name of the table and we can write the query for you.
Hope you understand…

My code that actually runs ok is this

while (\$arr = mysqli_fetch_assoc(\$res)) {
\$day = round((TIME_NOW - \$arr[‘added’]) / 86400);
… some code here …
}
and the print code is

(yes it prints correctly for daily usage)
im just trying to implement this into the query itself so i can pull it out lets say AS daily
so when im trying to print it to just use

" . mksize(\$arr['daily']) . " this way i would be able to sort the daily col asc or desc. atm it doesnt recognize the function and its not working

Again, you did not show us your table’s data structure. I will guess…