Welcome Guest, Not a member yet? Register   Sign In
Subcategory dropdown based on main category Codeigniter
#1

[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>&lt;?php echo $this->lang->line("catleather_a"); ?&gt;</strong></label>
  <div class="controls">  &lt;?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-&gt;lang-&gt;line("select")." ".$this->lang->line("catleather_a").'" title="'.$this-&gt;lang-&gt;line("pr_catleather_a_tip").'" required="required" data-error="'.$this-&gt;lang-&gt;line("catleather_a").' '.$this->lang->line("is_required").'"'); ?&gt; </div>
</p>

  <label class="control-label" for="subcatleather_a">&lt;?php echo $this->lang->line("subcatleather_a"); ?&gt;</label>
  <div class="controls" id="subcatleather_a_data"> &lt;?php
            $SubcatL_a[""] = '';

            echo form_dropdown('subcatleather_a', $SubcatL_a, '', 'class="span2" id="subcatleather_a"  data-placeholder="'.$this-&gt;lang-&gt;line("select_catleather_a_to_load").'"');  ?&gt; </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-&gt;lang-&gt;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;
#2

[eluser]webmarkcompt[/eluser]
Someone?
Any solution?
#3

[eluser]InsiteFX[/eluser]
Code:
$cat_name = "name";
$this->load_vars($cat_name);

Now it is global to any view part.
#4

[eluser]webmarkcompt[/eluser]
[quote author="InsiteFX" date="1412631919"]
Code:
$cat_name = "name";
$this->load_vars($cat_name);

Now it is global to any view part.
[/quote]

Thanks InsiteFX for reply

But.. how do I implement that in this code?
I've tried on the controller but don't know how to do that.

#5

[eluser]InsiteFX[/eluser]
You can added to your view
Code:
&lt;?php
$cat_name = "name";
$this->load_vars($cat_name);
?&gt;

#6

[eluser]webmarkcompt[/eluser]
[quote author="InsiteFX" date="1412638614"]You can added to your view
Code:
&lt;?php
$cat_name = "name";
$this->load_vars($cat_name);
?&gt;

[/quote]

Right...

But there is the issue.
In a normal query I would use the id of the record, as I think you suggested, but here the the goal is to insert the value of this register and not the id.

It has to do with the fact that they want the products remain unchanged after insertion, regardless of changes that will make the codes of the article (skin, lining, outsole). By the way, this is a invoice plataform for a shoes company.

So.. That's why I asked if there would be possibility to make the select, using the id to identify the subcategory, but enter the category name and not the ID...
This is possible?

Please take a look at the attachment.





Theme © iAndrew 2016 - Forum software by © MyBB