powpow Posted June 24, 2011 Share Posted June 24, 2011 I recently made a php script that retrieved a counter number from the database incremented it and then sent it back. I now want to give it more functionality and make it so I can create a monthly table with the totals for each page. To get a date I used sql function NOW(). I have run into some issues with how exaclty to play with it back on the php side. If I was planning on using this in comparision to date() and mktime() for some conditionals is there some "nice" way to do this. So far I have only come up with saving it into a string then retrieving the year and month (day doesn't matter for right now), and with those I can compare them against php functions. Any help would be appreciated Quote Link to comment https://forums.phpfreaks.com/topic/240269-retreiving-sql-now-for-page-hit-counter/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 24, 2011 Share Posted June 24, 2011 is there some "nice" way to do this Yes, do everything in your query statement. You can perform date comparisons with mysql DATE/DATETIME data types. There are also a couple of dozen date/time functions that would let you do things like extract the year/month from a DATE value so that you could match a range of dates in a query. retrieved a counter number from the database incremented it and then sent it back You can add a value to a column directly in the UPDATE query, you don't need to select the value first - UPDATE your_table SET counter = counter + 1 WHERE some_column = some_value Quote Link to comment https://forums.phpfreaks.com/topic/240269-retreiving-sql-now-for-page-hit-counter/#findComment-1234124 Share on other sites More sharing options...
powpow Posted June 24, 2011 Author Share Posted June 24, 2011 UPDATE your_table SET counter = counter + 1 WHERE some_column = some_value Thanks I will deffinitely try that. As for.... Yes, do everything in your query statement I didn't know you could do this in sql. I have to admit that I am stronger in php which is why I was looking at it from that perspective, but I am always willing to learn some thing new. This is a small example of what the table i am querying looks like: page_name counter DATE page 1 23 2011-5-10 12:34:33 page 2 23 2011-5-10 12:34:33 page 3 23 2011-5-10 12:34:33 The way I was going to go about this was to have a php variable set to the actual date it would increment when the month changed, if the month changed i would print the max count for each page under the specific month. My hopes are to make this work all the way up to anually. if you don't mind giving me some bread crumbs, maybe a link with a date compare or an example, I would appreciate it. I have already spent a little bit of time googling and havn't found what I need to grasp this concept. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/240269-retreiving-sql-now-for-page-hit-counter/#findComment-1234145 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.