mongoose00318 Posted July 2, 2008 Share Posted July 2, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/112876-solved-categorizing-dates/ Share on other sites More sharing options...
mongoose00318 Posted July 2, 2008 Author Share Posted July 2, 2008 Do I post my questions wrong or something? I seem to get limited or no answers at all when I post Quote Link to comment https://forums.phpfreaks.com/topic/112876-solved-categorizing-dates/#findComment-579776 Share on other sites More sharing options...
ababmxking Posted July 2, 2008 Share Posted July 2, 2008 The way i do it is by ID. since the newest post will have the highest id and oldest will have the oldest I do it by id. id being an auto_increment. Im still new to php so this might not be correct. Quote Link to comment https://forums.phpfreaks.com/topic/112876-solved-categorizing-dates/#findComment-579777 Share on other sites More sharing options...
mongoose00318 Posted July 2, 2008 Author Share Posted July 2, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/112876-solved-categorizing-dates/#findComment-579778 Share on other sites More sharing options...
ababmxking Posted July 2, 2008 Share Posted July 2, 2008 could add a spot in the database and have the posts update into a int the m number. so $month = date(m); if($db_month == '1'){ echo" whatever"; } something like that i spose would work but im sure theres an easier way to do it. Quote Link to comment https://forums.phpfreaks.com/topic/112876-solved-categorizing-dates/#findComment-579779 Share on other sites More sharing options...
mongoose00318 Posted July 2, 2008 Author Share Posted July 2, 2008 Hm..interesting I think that would work. I wonder if there is a more efficent way to do it with a loop using the timestamp already in the database? Quote Link to comment https://forums.phpfreaks.com/topic/112876-solved-categorizing-dates/#findComment-579782 Share on other sites More sharing options...
ababmxking Posted July 2, 2008 Share Posted July 2, 2008 idk maybe. my php skills are limited lol. Quote Link to comment https://forums.phpfreaks.com/topic/112876-solved-categorizing-dates/#findComment-579783 Share on other sites More sharing options...
mongoose00318 Posted July 2, 2008 Author Share Posted July 2, 2008 Lol no problem so are mine, that's why I am in here I appreciate your advice anyways. Quote Link to comment https://forums.phpfreaks.com/topic/112876-solved-categorizing-dates/#findComment-579784 Share on other sites More sharing options...
mongoose00318 Posted July 2, 2008 Author Share Posted July 2, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/112876-solved-categorizing-dates/#findComment-579793 Share on other sites More sharing options...
ababmxking Posted July 2, 2008 Share Posted July 2, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/112876-solved-categorizing-dates/#findComment-579800 Share on other sites More sharing options...
mongoose00318 Posted July 2, 2008 Author Share Posted July 2, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/112876-solved-categorizing-dates/#findComment-579806 Share on other sites More sharing options...
ababmxking Posted July 2, 2008 Share Posted July 2, 2008 No problem. Glad I could help you. Quote Link to comment https://forums.phpfreaks.com/topic/112876-solved-categorizing-dates/#findComment-579807 Share on other sites More sharing options...
mongoose00318 Posted July 2, 2008 Author Share Posted July 2, 2008 ya it turns out the (date_column) was just the database field that you have the date stored in...just for future reference Quote Link to comment https://forums.phpfreaks.com/topic/112876-solved-categorizing-dates/#findComment-579808 Share on other sites More sharing options...
ababmxking Posted July 2, 2008 Share Posted July 2, 2008 awww ok so it would look like this to select january SELECT * FROM blog WHERE MONTH date= 1; Quote Link to comment https://forums.phpfreaks.com/topic/112876-solved-categorizing-dates/#findComment-579810 Share on other sites More sharing options...
mongoose00318 Posted July 2, 2008 Author Share Posted July 2, 2008 yep as long as date is your field in the db that holds the date. Quote Link to comment https://forums.phpfreaks.com/topic/112876-solved-categorizing-dates/#findComment-580207 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.