logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 04-27-2012, 06:53 PM   #1
tony09uk
 
Join Date: Oct 2010
Posts: 340
Default Displaying article

I need to display each month an article was posted e.g

APRIL

MARCH

FEBRUARY

DECEMBER

OCTOBER

etc....

I want to display the twelve previous months that articles have been posted but only want each to be displayed once, no matter how many times articles have been posted that month (the user will click on the month to view the articles from that month).

I have created this:

$months = mysql_query("SELECT article_id, content, DATE_FORMAT(date, '%M')
AS date
FROM article
ORDER BY article_id
DESC
LIMIT 12");


while($row = mysql_fetch_array($months)){
echo $row['date'] . "<br/>";
}

trouble is with the above code, if 12 articles were posted in April then April would show 12 times, how do I stop this from happening?
tony09uk is offline   Reply With Quote
Old 04-28-2012, 01:53 AM   #2
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

read this http://www.dreamincode.net/forums/to...s-spreadsheet/
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 04-29-2012, 03:41 PM   #3
tony09uk
 
Join Date: Oct 2010
Posts: 340
Default

I didn't really get much from that post, but thanks for the link.

I have now got it sorted, for anyone else suffering a similar issue use

SELECT DISTINCT MONTH(date) FROM article ...
tony09uk is offline   Reply With Quote
Old 04-30-2012, 01:37 AM   #4
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

that was meant for another post about xls sheets, i have no idea why i put it here. In my defenc im old and i dribble when bored
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 05-06-2012, 09:44 PM   #5
tony09uk
 
Join Date: Oct 2010
Posts: 340
Default

I am currently trying to select all the articles from a specific month.

I.e. select January and all six posts from that month will be displayed etc...

I have tried a few ways out but all with seemingly no success. How is it done?
tony09uk is offline   Reply With Quote
Old 05-07-2012, 01:50 AM   #6
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

depends but in some layouts you could use

$date="january"; ///or $date=$_post['month'];
where date =$month
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 05-07-2012, 11:50 AM   #7
tony09uk
 
Join Date: Oct 2010
Posts: 340
Default

Ok, in the address bar it says pagename?id=january. So does php january febuary etc as months or does it see it as just another string? I think i have tried WHERE id=month
tony09uk is offline   Reply With Quote
Old 05-08-2012, 12:57 AM   #8
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

so its a $_GET['pagename'] value.
echo out your values to check what you have. id is unlikely to be the month is it.
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 05-08-2012, 08:05 AM   #9
tony09uk
 
Join Date: Oct 2010
Posts: 340
Default

in the address bar it comes up as id=january when i click on the january option.

However i have been wondering can i break up the date. It is set as day-month-year. Is this saved as an array? and if so can i break it up and use them that way?
tony09uk is offline   Reply With Quote
Old 05-08-2012, 08:24 AM   #10
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

yes sorry rushing again, $_GET['id] you could explode using "-"as separator, or download the timestamp and format then.
read this http://www.tizag.com/phpT/phpdate.php
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:21 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com