0

I want to develop a edit form for newsletter. I have done this but i can't load category list in same view.

if user click on newsletter its open in edit view, in this edit view i want to give him a option for category selection option. categories are stored in different table name cat.

i have tried it but its showing only one category.

Please help me am new in Php

1 Answer 1

1

Well, without any actual code examples, this is going to de pretty tough... Presumably the edit view is a form, and you are using the form helper to generate a dropdown field.

The first thing you need are the categories in the right format to be displayed in the dropdown.

From the CodeIgniter docs :

$options = array(
                  'small'  => 'Small Shirt',
                  'med'    => 'Medium Shirt',
                  'large'   => 'Large Shirt',
                  'xlarge' => 'Extra Large Shirt',
                );

where the array keys are your options values and the array values are the text displayed.

You need to get your categories in this format with your model. I tend to use the id as the option value, so you could have a function like this in your model:

function get_cat(){
  $q=$this->db->get('cat');
  if ($q->num_rows()>=1){
    foreach($q->result() as $row){
      $data[$row->id]=$row->name;
    }
    return $data
  }else{
    return false;
  }
}

and assuming your controller passes the result of that function to the view, you can just do this in your view :

echo form_dropdown('categories', $data);

As a closing note, you might want to start on PHP by developping some things from scratch, not using a framework, you should learn a lot more that way. Just my opinion.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks you jfoucher, you are right i have to learn first PHP then use any Framework
Can you suggest me a book for php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.