some db statistics and order

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
adamrain
Forum Newbie
Posts: 15
Joined: Thu Jun 03, 2010 5:35 am

some db statistics and order

Post by adamrain »

ok i have two things i need to do with a table in db which is called relation, it represents relations between a lot or other tables.

first thing i need is statistics of last created relations by date somthing that will output like "comments per week 00.9,less then last week".

second thing i need is to call just the last 5 rows of the table (here i can do the rest and output the data any way i want).
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: some db statistics and order

Post by Jonah Bron »

To calculate the comments per week, just divide the number of comments by the amount of time it's been up.
adamrain
Forum Newbie
Posts: 15
Joined: Thu Jun 03, 2010 5:35 am

Re: some db statistics and order

Post by adamrain »

ok thats helpful thank you

but how do i call the last 5 rowes of a table in mysql?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: some db statistics and order

Post by Jonah Bron »

Assuming you have a auto-increment column `id`, the SQL will look like this:

Code: Select all

SELECT * FROM my_table ORDER BY id DESC LIMIT 5
adamrain
Forum Newbie
Posts: 15
Joined: Thu Jun 03, 2010 5:35 am

Re: some db statistics and order

Post by adamrain »

thank you thats awsome!
(i always use id its a comfortable way to manipulate data)
Post Reply