[eluser]webmarkcompt[/eluser]
Hello everyone
How can I insert value of the category (code) instead of category id in the mysql database? This is the main category select code
Code:
<div class="control-group">
<label class="control-label" for="catleather_a"><strong><?php echo $this->lang->line("catleather_a"); ?></strong></label>
<div class="controls"> <?php
$catL_a[''] = "";
foreach($catleathers as $category) {
$catL_a[$category->id] = $category->code;
}
echo form_dropdown('catleather_a', $catL_a, set_value('catleather_a'), 'class="tip chzn-select span2" id="catleather_a" data-placeholder="'.$this->lang->line("select")." ".$this->lang->line("catleather_a").'" title="'.$this->lang->line("pr_catleather_a_tip").'" required="required" data-error="'.$this->lang->line("catleather_a").' '.$this->lang->line("is_required").'"'); ?> </div>
</p>
<label class="control-label" for="subcatleather_a"><?php echo $this->lang->line("subcatleather_a"); ?></label>
<div class="controls" id="subcatleather_a_data"> <?php
$SubcatL_a[""] = '';
echo form_dropdown('subcatleather_a', $SubcatL_a, '', 'class="span2" id="subcatleather_a" data-placeholder="'.$this->lang->line("select_catleather_a_to_load").'"'); ?> </div>
</div>
This is the depend subcategory select controller
Code:
function getSubCatLeathers_a()
{
$category_id = $this->input->get('category_id',TRUE);
if($rows = $this->products_model->getSubCatLeathersByCatLeatherID($category_id)) {
$catL_a[""] = '';
foreach($rows as $category){
$catL_a[$category->code] = $category->code;
}
$data = form_dropdown('subcatleather_a', $catL_a, '', 'class="span2" id="subcatleather_a" data-placeholder="'.$this->lang->line("select")." ".$this->lang->line("subcategory").'"');
} else {
$data = "";
}
echo $data;
}
The subcategory is saving the name in the line $catL_a[$category->code] = $category->code;
But I can't do the same at main category cause I need the ID to select subcategory.
Is any way to overcome this?
Tables
Code:
CREATE TABLE IF NOT EXISTS `subcatleathers` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`category_id` int(11) NOT NULL,
`code` varchar(55) NOT NULL,
`name` varchar(55) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `catleathers` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`code` varchar(55) NOT NULL,
`name` varchar(55) NOT NULL,
PRIMARY KEY (`id`),
KEY `id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;