$connection = new PDO("mysql:dbname=library;host=127.0.0.1;charset=utf8", "library_admin", "123456"); $db = new NotORM($connection); $booksBySeries = []; $books = $db->BooksByAuthor()->where("aid = ?", $aid); if ($deleted) { $books = $books->where("Deleted <> ?", 1); } if ($lang) { $books = $books->where("lang = ?", $lang); } $booksBySeries["count"] = count($books); $noseq = []; $seq = []; /* @var $book type */ foreach ($books as $book) { $series = $db->BooksBySerie()->where("bid = ?", $book["bid"]); if (count($series) > 0) { foreach ($series as $serie) { $book["sn"] = $serie["sn"]; if (array_key_exists($serie["sid"], $seq)) { array_push($seq[$serie["sid"]]["books"], $book); } else { $seq[$serie["sid"]]["name"] = $serie["seqname"]; $seq[$serie["sid"]]["books"] = [$book]; } } } else { $noseq[$book["bid"]] = $book; } } $booksBySeries["noseq"] = $noseq;