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