Jump to content
php.lv forumi

Foruma kategoriju un subkategoriju attēlošana Kohana Framework


reGative

Recommended Posts

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 ]

Link to comment
Share on other sites

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 by reGative
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...