0

Hi I am trying to create a dropdown using a CI forms. I have a table reseller and in that i have a field called Key. Now I have another table Users where i store user's information. I want to create a new user and in that user creation form i have a drop down field called Key where i want to fetch the key of all the resellers. So that i can identify which user is mapped to which reseller using that key.

For Controller I have done this :

$data = $this->user_m->array_from_post(array('sip_id','sip_pass','name','key','email', 'password','phone','status','created','balance')); $this->load->model('reseller_m'); $this->data['resellers'] = $this->reseller_m->get('key'); $data['password'] = $this->user_m->hash($data['password']); $key=$this->user_m->save($data, $id); redirect('admin/user'); } $this->data['subview'] = 'admin/user/add'; $this->load->view('admin/_layout_main', $this->data); 

The View is

<tr> <td>Key</td> <?php if(count($resellers)): foreach($resellers as $reseller) ?> <td><?php echo form_dropdown('key', set_value('key', $user->key));?></td> </tr> 

But i dont get anything on screen. So How to create this drop-down?

5
  • is the : after if(count($resellers)) a typo or intentional? Commented Sep 12, 2015 at 6:52
  • @Blip actually i copied it from an example : <tr> <td>Status</td> <td><?php echo form_dropdown('status', array('Active' => 'active', 'Inactive' => 'inactive', 'Delete' => 'delete'), $this->input->post('status') ? $this->input->post('status') : $user->status ); ?></td> </tr> Commented Sep 12, 2015 at 6:54
  • in your last comment, there is a ternary if else operator (condition)?true : false which you are not using in your method that you have posted. So remove the : and check out. Commented Sep 12, 2015 at 6:59
  • i did that as well but not working i also did this <tr> <td>Key</td> <?php if(count($resellers)): foreach($resellers as $reseller) ?> <td><?php echo form_dropdown($reseller = array($reseller->id,$reseller->key));?></td> </tr> Commented Sep 12, 2015 at 7:02
  • i have updated the question code please check @jalpa Commented Sep 12, 2015 at 8:28

1 Answer 1

3

Can you please try it like this:

 <tr> <td>Key</td> <?php if(count($resellers) > 0) { foreach($resellers as $reseller) { ?> <td> <?php echo form_dropdown('key', set_value('key', $user->key));?> </td> <?php } } ?> </tr> 

Is this variable right: $user->key? I think you need to use: $reseller->key.

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

11 Comments

thanks for the answer in my crontroller i do this : $this->data['resellers'] = $this->reseller_m->get(); but then also i get an error undefined value Reseller
@Rajan Can you please tell me what value store in this array $resellers ? i mean in this $this->data['resellers'] = $this->reseller_m->get();
i should have been blank coz i am trying to fetch the reseller values in user controller
how do i pass that key of reseller from my controller to view?
any idea where i am wrong in my controller i did this :$this->data['resellers'] = $this->reseller_m->get()
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.