Jump to content

Recommended Posts

Hey all!

 

I was wondering how I would go about categorizing entries from a database by date? Say like this...

 

January

--------

Article 1

Article 2

 

Febuary

--------

Article 1

Article 2

 

etc..

 

I figure there would be some kind of loop or a conditional statement to make it happen but I have no clue how to do either on a date/timestamp.  ??? Any suggestions?

Link to comment
https://forums.phpfreaks.com/topic/112876-solved-categorizing-dates/
Share on other sites

No, that wouldn't work I don't think because say it has been a year from the first post then the newest and oldest ID would be associated with the same month. I have the dates stored with a UNIX timestamp in the database. I am just wondering if there is a way to do something like...

 

if(date(m) == 1) {

echo date();

}

 

I don't know?

Hm, a thought came to mind. Could you do something like this?

 

$current_month = 1;

 

while($current_month <= 12) {

mysql_query = "SELECT * FROM blog WHERE date_entered='$current_month'";

//echo results

$current_month++;

}

 

Except I don't know how I could compare the $current_month to a timestamps month. Would this work if it was correctly written, if so how would I compare the months?

i found something for ya.

 

SELECT * FROM table_name WHERE MONTH(date_column) = 4;

 

not sure what (date_column) = 4; is but maybe someone can shed some light on it.

 

edit

 

might search google for something like "how to select month from a datetime" thats how i found that above.

Yes I found that code. I edited it a bit and it is pulling just the certain month from the db. Pretty cool, that is one piece to the puzzle of what I am trying to create. I am going leave it at that for the night heh but thank you, you helped out alot! I will continue on tomorrow.

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.