Welcome Guest, Not a member yet? Register   Sign In
drop down with category and subcategory
#11

[eluser]Bigil Michael[/eluser]
public function getAllCategoriesSelector($first_option = 'Please select...') {

what will be the value in 'Please select...'
#12

[eluser]Bigil Michael[/eluser]
[quote author="SPeed_FANat1c" date="1303915482"]
Code:
function create_dropwdown()
{
$query = 'select * from table';

$html = '<select name="mydropdown">'

foreach($query->result() as $row )
{
  if($row->parent == 0)
     $html .= '<option class = "category" value="'.$row->id.'">'.$row->heading.'</option>';
  else $html .= '<option class = "not_category" value="'.$row->id.'">'.$row->heading.'</option>';
}

$html .= '</select>';

return $html;
}

Something like this. I havent tested it. You can now use css to change color for option where class = "category"[/quote]

can u split this into
model view and controller?
i didn't understand which is the controller portion, model and view
#13

[eluser]louisl[/eluser]
The value will be nothing so you can check if at least one item's been selected by using required
#14

[eluser]SPeed_FANat1c[/eluser]
[quote author="Bigil MM" date="1303924265"][quote author="SPeed_FANat1c" date="1303915482"]
Code:
function create_dropwdown()
{
$query = 'select * from table';

$html = '<select name="mydropdown">'

foreach($query->result() as $row )
{
  if($row->parent == 0)
     $html .= '<option class = "category" value="'.$row->id.'">'.$row->heading.'</option>';
  else $html .= '<option class = "not_category" value="'.$row->id.'">'.$row->heading.'</option>';
}

$html .= '</select>';

return $html;
}

Something like this. I havent tested it. You can now use css to change color for option where class = "category"[/quote]

can u split this into
model view and controller?
i didn't understand which is the controller portion, model and view[/quote]

This function probalby would fit in model.

So now the controller index function:

Code:
function index()
{
  $this->load->model('dowpdown_model');
  $data['dropdown'] = $this->dowpdown_model->create_dropwdown();

  $this->load->view('your_page_view',$data);
}

And view:

Code:
...some html...

&lt;?php echo $dropdown ?&gt;

...some ohter html...
#15

[eluser]Bigil Michael[/eluser]
sorry to say that

my problem is not fully solved

if my table structure is like this

Quote:id parent heading
1 o test
2 1 t1
3 1 t2
4 0 kerala
5 4 k1
6 4 k2
7 1 t3
8 4 k3
result like this

can any one help me please????


Quote:test
t1
t2
t3
kerala
k1
k2
k3
here it doesnot print the correct result

my code is like this
model
Quote:function select_category()
{
$this->db->distinct();
$result_category = $this->db->get('classifieds_categories');
return $result_category->result_array();
}
view
Quote:<select name="category" >
<option value="">--Select--</option>
&lt;?php
foreach($category as $row)
{
?&gt;

&lt;?php if($row['parent']== 0) {?&gt;
<option value="&lt;?php echo $row['id']?&gt;" >&lt;?php echo $row['heading']?&gt;</option>
&lt;?php } else {?&gt;
<option value="&lt;?php echo $row['id']?&gt;" >&lt;?php echo $row['heading']?&gt;</option>
&lt;?php }?&gt;
&lt;?php
}
?&gt;
</select>
controller
Quote:&lt;?php
class Member_classifieds extends Controller {
function Member_classifieds(){
parent::Controller();
$this->load->model(‘Member_classifieds_model’);

}
function add(){

$data[‘category’] = $this->Member_classifieds_model->select_category();
if($this->input->post(‘Submit’)){
$config = array(
array(‘field’ => ‘category’,‘label’ => ‘Ads Category’, ‘rules’ => ‘required’),

);
$this->form_validation->set_rules($config);
if ($this->form_validation->run() == FALSE)
{
$this->load->view(‘member_classifieds/add’, $data);
}else{
$this->Member_classifieds_model->save(‘Add’);
redirect(‘member_classifieds’);
}
}else{
$this->load->view(‘member_classifieds/add’, $data);
}

}
}
?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB