1

How to Get Data by id or other value From Static Dropdown? This My View :

        <select name="status" id="status" class="form-control">
            <option selected="selected" value="1">ACTIVE</option>
            <option value="2">INACTIVE</option>
        </select>

        <!--- GET DATA FROM DB WHERE STATUS DROPDOWN --> 
        <select name="result" id="result">
          <option selected="selected" value="">ALL</option>
        </select>

My Model :

function get($status){
    $query = $this->db->get_where('people', array('status' => $status));
    return $query;
}

My Controller :

function getresult(){
    $status= $this->input->post('status',TRUE);
    $data = $this->people_model->get($status)->result();
    echo json_encode($data);
}

and My Ajax : enter image description here

I tried This but no Working Please Help

1 Answer 1

1

I think you should get the value of id instead of status in your controller function because that's what you're sending via ajax-

function getresult(){
    $status= $this->input->post('id',TRUE);
    $data = $this->people_model->get($status)->result();
    echo json_encode($data);
}

See if this works for you, everything else seems fine to me.

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

3 Comments

That's weird. Everything else seems fine to me, I even made a demo and it's working for me. The only thing I can say at this point is to check the path(url) of the controller function getresult() and name of the model people_model, also make sure that you've loaded people_model before calling it. See if it helps.
ops, my bad i got mistake in writing code.. Thank you very much sir.. You Save My Day
Happy to help. :)

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.