Jump to content

Recommended Posts

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  :D   

Link to comment
https://forums.phpfreaks.com/topic/240269-retreiving-sql-now-for-page-hit-counter/
Share on other sites

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

 

 

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.