Hi... I've been programming for years but I've never been stumped like this. Please help!!!!
I'm new to silverstripe and I've been searching for two days and can't seem to find a GOOD tutorial on how to do a simple sql query in my NewsPage.php and then retrieve the results in my NewsPage.ss
I need to translate the query: SELECT DISTINCT SUBSTRING(`Date`,1,4) AS Year FROM `ArticlePage`
using the 'DataObject::get' method.
If anyone can translate the above query into something like the function below, I will be eternally grateful!!!!!!!!!!!!!!!!
/*EXAMPLE FUNCTION For NewsPage.php*/
function NewsYear($num=3) {
$news = DataObject::get_one("NewsPage");
return ($news) ? DataObject::get("ArticlePage", "ParentID = $news->ID", "Date DESC", "", $num) : false;
//SELECT * FROM
}
/*EXAMPLE CODE For NewsPage.ss*/
<% control NewsYear %>
$Year
<% end_control %>
God bless!