2

I have a problem using Silverstripe CMS. I have basic SQL query of which results I would like to display in our front-end.i just want to use DB::query & get the result in our front- end. Can anyone help or please give me a hint?

public function LetestNews() {
    $result[] = DB::query("SELECT t.* , (SELECT f.Name FROM File f, NewsArticle n WHERE n.ID = t.ID AND n.AttachedImageID = f.ID LIMIT 0,1) as image FROM `SiteTree` t WHERE t.ClassName LIKE '%NewsArticle%' ORDER BY t.LastEdited DESC LIMIT 0,3");

          $masterLocationArray = [];

             foreach( $result as $key => $data ) {
                $locationArray = [];
                foreach($data as $item) {
                    $locationArray[] = $item;
                }

                $masterLocationArray[$key] = $locationArray;
             }

             return $masterLocationArray;
          }

  //For the .ss template file I'm using that code <br/>
      <!-- Letest News Sections -->
            $LetestNews
      <!-- End Latest News Sections -->
HP371
  • 860
  • 11
  • 24
saurabh
  • 21
  • 3
  • Hey, I got the solution The DB::query user array list $list = ArrayList::create(); we need to use array list under foreach for retrive the data – saurabh Dec 11 '19 at 09:30
  • 1
    You should post that as an answer and mark it as accepted – scrowler Dec 13 '19 at 00:58

0 Answers0