samedi 26 septembre 2015

Can this query be done on a file based sqlite database with PDO?

Trying to figure out if it is possible to do this query with PDO on a sqlite database. I am struggling with CROSS JOIN on a single table.

public function get_menuItems() {
    $result = $this->database->query("SELECT * FROM menu_items ");
    if ($this->database->num_rows($result)) {
        $right = array();
        $result = $this->database->query("SELECT node.title, node.type, node.class_name, node.content, node.id AS id, node.lft AS lft, node.rgt AS rgt, (COUNT(parent.title) - 1) AS depth FROM menu_items AS node CROSS JOIN menu_items AS parent WHERE node.lft BETWEEN parent.lft AND parent.rgt GROUP BY node.id ORDER BY node.lft");

        $tree = array();
        while ($row = mysql_fetch_assoc($result)) {
            $tree[] = $row;
        }
    } else {
        $tree = false;
    }
    return $tree;
}

Aucun commentaire:

Enregistrer un commentaire