Portal Home > Knowledgebase > Articles Database > Sql: Select all posts of 2008 and a specific month


Sql: Select all posts of 2008 and a specific month




Posted by vince2doom, 12-18-2008, 11:38 AM
Sql: Select all posts of 2008 and a specific month Hi all, I've got a question, I'm trying to make an archive. I'm using UNIX timestamps. This is my query: PHP Code: $sql->query('SELECT DISTINCT MONTHNAME(FROM_UNIXTIME(datum)) as `month`,ÂÂ* ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*YEAR(FROM_UNIXTIME(datum)) as `year`, ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*MONTH(FROM_UNIXTIME(datum)) as `monthNum` ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*FROM `Nieuws` ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*WHERE `year` = '.$link->stuk(2).' ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ORDER BY `year` ASC, `monthNum` ASC'); But I get the error: Quote: Unknown column 'year' in 'where clause' I defined year, so why doesn't it work ? Thanks in advance !

Posted by jaseeey, 12-18-2008, 12:07 PM
Does the attribute 'year' exist in the database table? EDIT: Sorry, scratch that. Just realised what you have done in the query.

Posted by vince2doom, 12-18-2008, 12:09 PM
Quote: Originally Posted by Jaseeey Does the attribute 'year' exist in the database table? No, I'm working only with the field "datum".

Posted by jaseeey, 12-18-2008, 12:11 PM
Okay, I have done a quick search. I'm not 100% sure on this myself, but this URL may outline a few things. URL: http://stackoverflow.com/questions/1...n-where-clause

Posted by vince2doom, 12-18-2008, 02:45 PM
Quote: Originally Posted by Jaseeey Okay, I have done a quick search. I'm not 100% sure on this myself, but this URL may outline a few things. URL: http://stackoverflow.com/questions/1...n-where-clause Hey thanks that helped PHP Code: $sql->query('SELECT DISTINCT MONTHNAME(FROM_UNIXTIME(datum)) as `maand`,ÂÂ* ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*YEAR(FROM_UNIXTIME(datum)) as `jaar`, ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*MONTH(FROM_UNIXTIME(datum)) as `maandNum` ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*FROM `Nieuws` ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*ÂÂ*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