Web Hosting Talk







View Full Version : Sql: Select all posts of 2008 and a specific month


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 !

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.

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".

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

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`
テつ*テつ*テつ*テつ*テつ*テつ*テつ*テつ*テつ*テつ*テつ*テつ*テつ*テつ*テつ*テつ*テつ*テつ*テつ*テつ*HAVING `jaar` = "'.$link->stuk(2).'"
テつ*テつ*テつ*テつ*テつ*テつ*テつ*テつ*テつ*テつ*テつ*テつ*テつ*テつ*テつ*テつ*テつ*テつ*テつ*テつ*ORDER BY `jaar` ASC, `maandNum` ASC');

Jaseeey
12-18-2008, 08:20 PM
No problems mate, glad you could get it fixed!