1
// Get all categories
$query = "SELECT name FROM bolt_taxonomy WHERE taxonomytype = :taxonomytype AND contenttype = :contenttype";
$map = array(
    ':taxonomytype'  => 'categories',
    ':contenttype' => 'news',
);
$categories = $this->app['db']->fetchAssoc($query, $map);

$response = $this->app->json(array('categories' => $categories));
return $response;

Returns:

{
    "categories": {
        "name": "life"
    }
}

Which is just the first entry that matches the above condition on the bolt_taxonomy table. How can I get it to return the whole list of categories?

babbaggeii
  • 7,577
  • 20
  • 64
  • 118

2 Answers2

1

This is now solved by using fetchAll:

// Get the category
    $query = "SELECT name FROM bolt_taxonomy WHERE taxonomytype = 'categories' AND contenttype = 'news'";

    $categories = $this->app['db']->query($query);
    $result = $categories->fetchAll();

    $response = $this->app->json(array('categories' => $result));
    return $response;
babbaggeii
  • 7,577
  • 20
  • 64
  • 118
0

You need to populate using while or foreach loop.

$categories = $this->app['db']->fetchAssoc($query, $map);

foreach($categories as $category) {
   $result[] = $category;
}
$response = $this->app->json($result);
echo $response;
return $response;
Ranjith
  • 2,779
  • 3
  • 22
  • 41