Getting info for the last six months - dates problem

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
tamiya
Forum Newbie
Posts: 14
Joined: Mon Feb 06, 2006 7:19 am

Getting info for the last six months - dates problem

Post by tamiya »

I need to know how to design the dates part of my code in order to dynamically get data from my db for the last six months, and then display the info, per month. Remember, this all has to happen dynamically, its for a statistics report...

Any code examples or general tips would help a great deal

Thanks so long
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

What does your table look like? Mysql has some great date and time functions that can help you...

http://dev.mysql.com/doc/refman/5.0/en/ ... tions.html
tamiya
Forum Newbie
Posts: 14
Joined: Mon Feb 06, 2006 7:19 am

Post by tamiya »

this is a replica of what the actual output of data should have had to look like....

Code: Select all

[color=green]<table>
   <tr>
     <td></td><td>Feb</td><td>Jan</td><td>Dec</td><td>Nov</td><td>Oct</td><td>Sep</td>
     <td>Clients</td><td>Feb Info</td><td>Jan Info</td><td>Dec Info</td><td>Nov Info</td><td>Oct Info</td><td>Sep Info</td>
   </tr>
</table>[/color]
Then, eventually, i figured out how to get the information, using variables: eg var1, var2, var3 by running a while loop, to increment the number after 'var' and then display.
But... that made the info display underneath each other:

Code: Select all

[color=green]<tr><td>Feb Info</td></tr>
<tr><td>Jan Info</td></tr>
<tr><td>Dec Info</td></tr>
<tr><td>Nov Info</td></tr>
<tr><td>Oct Info</td></tr>
<tr><td>Sep Info</td></tr>[/color]
...which is not what i wanted.
So, after much pondering and then some, i just realised, shortcuts wont work in this case....

i posted this this morning, but i think it got blocked, cos i didnt put code tags around the code. did that and my problem is sorted out now, thanks, but now i have another problem:

How would i go about getting the top 10 entries for a certain month?
eg. there are a hundred projects in my database (msql) and i would like to see which 10 were viewed the most during the last month...
Last edited by tamiya on Tue Feb 07, 2006 3:13 am, edited 1 time in total.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

hawleyjr wrote:What does your table look like?
You still haven't answer this question...it is hard to recommend any method without the basic info
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

tell us about ur database tables? how do they look like?
tamiya
Forum Newbie
Posts: 14
Joined: Mon Feb 06, 2006 7:19 am

Post by tamiya »

this problem is solved, thanks for all your help. for each month, to display the data in vertical order, i had to duplicate the code six times. it was long and tedious work, although, if i think about it now, i could have probably done it quicker, using loops. but, main thing is, its working fine.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Sounds very inefficient, but if you happy with it :D
tamiya
Forum Newbie
Posts: 14
Joined: Mon Feb 06, 2006 7:19 am

Post by tamiya »

if i've got time left, i'll go back and rewrite this, but for now, it displays fine, and that is what we need to present to the users in a lil while...

or i'll just leave it for when the next junior comes along to fix, as i had to do in my first week or so
Post Reply