reGative Posted January 7, 2012 Report Share Posted January 7, 2012 Labdien! Apgūstu Kohana Framework. Izmantoju 3.2 versiju. Vajag palīdzību sakarā ar foruma kategoriju un apakškategoriju attēlošanu. Kā tas veicams? Quote Link to comment Share on other sites More sharing options...
briedis Posted January 7, 2012 Report Share Posted January 7, 2012 Kontrolierī, izsaucot attiecīgo modeļa metodi, atlasi kategoriju sarakstu, padod skatam, un skatā izdrukā sarakstiņu. Kur problēmas? Vispār, šai problēmai īsti nav nekāda sakara ar ietvaru, ko lieto... Quote Link to comment Share on other sites More sharing options...
reGative Posted January 7, 2012 Author Report Share Posted January 7, 2012 Ir viena lieta - man vajag attēlos apakškategorijas attiecīgi zem kategorijām - Kategorija 1 - Subkategorija 1 Kategorija 2 - Subkategorija 2 Quote Link to comment Share on other sites More sharing options...
briedis Posted January 7, 2012 Report Share Posted January 7, 2012 Nu parādi, ko tu esi sarakstījis līdz šim, parādi arī kāda ir tabulas struktūra. Quote Link to comment Share on other sites More sharing options...
reGative Posted January 7, 2012 Author Report Share Posted January 7, 2012 CREATE TABLE IF NOT EXISTS `subcategories` ( `id` int(11) NOT NULL AUTO_INCREMENT, `category_id` text NOT NULL, `name` text NOT NULL, `description` text NOT NULL, `posts_count` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ; CREATE TABLE IF NOT EXISTS `categories` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` text NOT NULL, `description` text NOT NULL, `posts_count` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ; Modelis - public function get_categories(){ return $query = DB::query(Database::SELECT, 'SELECT * FROM categories ORDER BY id DESC')->execute()->as_array(); } public function get_cat_id(){ return $query = DB::query(Database::SELECT, 'SELECT id FROM categories')->execute()->as_array(); } Class Model_Subcategory Extends Model { public function get_subcategories($id){ return $query = DB::query(Database::SELECT, 'SELECT * FROM subcategories WHERE category_id = :id ORDER By id DESC') ->parameters(array( ':id' => $id, ))->execute()->as_array(); } } } Kontrolieris - public function action_index() { $model_for_categories = Model::factory('category'); $model_for_subcategories = Model::factory('subcategory'); $model_for_list = $model_for_categories->get_categories(); $model_for_cat_id = $model_for_categories->get_cat_id(); $model_for_s_list = $model_for_subcategories->get_subcategories($model_for_cat_id); $view = View::factory('home/index'); $categories = $view->set('categories', $model_for_list); $subcategories = $view->set('subcategories', $model_for_s_list); $this->template->content = $view->render(); } Errors - Operand should contain 1 column(s) [ SELECT * FROM subcategories WHERE category_id = (('1'), ('2')) ORDER By id DESC ] Quote Link to comment Share on other sites More sharing options...
reGative Posted January 7, 2012 Author Report Share Posted January 7, 2012 Esmu velti lūdzis šeit palīdzību? Quote Link to comment Share on other sites More sharing options...
briedis Posted January 7, 2012 Report Share Posted January 7, 2012 Kas šī par mistisku sintaksi? WHERE category_id = (('1'), ('2')) Ja vajag vairākus id, tad var WHERE category_id IN (1,2,3,4,5,6) vai WHERE category_id = 1 OR category_id = 2 OR category_id = 3 ... Quote Link to comment Share on other sites More sharing options...
reGative Posted January 7, 2012 Author Report Share Posted January 7, 2012 (edited) Brīnos, ka nesaprati no koda. Īsāk sakot ņem to kategorijas id laukā un liek tai funkcijā, lai meklē apakškategorijas pēc kategorijas id. Kā ar attēlojumu būs,nezinu. Tjip es nelieku kategorijas id pats, to liek funkcija. Tagad sintakse errorā šāda -SELECT * FROM subcategories WHERE category_id = (('1'), ('2')) OR category_id = (('1'), ('2')) ORDER By id DESC Edited January 7, 2012 by reGative Quote Link to comment Share on other sites More sharing options...
edw Posted January 7, 2012 Report Share Posted January 7, 2012 Tev tak tikko pateica kā jādara, ko vēl nesaproti? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.