Reply to Re: Displaying records from current month only

Your name:

Reply:


Posted by Ehsan on 04/04/06 10:43

Probably you are using mysql 3.x.x. The function SUBDATE() is in mysql
4.1.1+. You can use DATE_SUB() instead. You will require SUBDATE(NOW(),
INTERVAL 31 DAY).

I also have category in my blog. for that you will have a seperate
table for category whose ID field will be a foreign key in your blog
table. I used left join to perform the count. Following is my sql:

SELECT s.*, COUNT(b.id) as totalPost FROM section_tbl AS s LEFT JOIN
blog_tbl AS b ON (s.id = b.sec_id) WHERE s.status = 'active' GROUP BY
b.sec_id

For number of posts in a month the sql goes as follows:

SELECT CONCAT(MONTHNAME(b.post_date_time), ' ', YEAR(b.post_date_time))
as postMonYear, MONTH(b.post_date_time) as postMonth, COUNT(b.id) as
totalBlogs from blog_tbl AS b LEFT JOIN section_tbl AS s ON (b.sec_id =
s.id) WHERE s.status = 'active' AND b.status = 'active' AND b.private =
'no' GROUP BY CONCAT(MONTH(post_date_time), ' ', YEAR(post_date_time))
ORDER BY post_date_time ASC

I Print postMonYear - totalBlogs and then in anchor tag I used
postMonth to set the link. So the tag is:

<a
href='blogscript.php?month=<?=$obj->postMonth?>'><?=$obj->postMonYear?>
- <?=$obj->totalBlogs?></a>

Same thing is done for Section/Category.

Hope this helps.

Thanks and God Bless!!

Ehsan

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация