1

I don't know if I formulated this question correctly but let me try to explain myself better.
I have following menu on my page that outputs new result once new selection is choosen: select menus

Izaberite pol: and Izaberite studente: contains 3 options each oba, zenski, muski and oba, stari, novi respectively.

I've added some Javascript to recognise option changing and automatically call controller action:

$("select.filter").change(function () {
    var str = "";
    $("select option:selected").each(function () {
        str += $(this).attr('value') + "/";
    });
    window.open("http://vipassana-srbija.comli.com/index.php/login/trust/"+str,"_self");
});

As you can see from Javacript code it will call controller's Login trust function:

public function trust($tabela="letnji",$pol="oba", $student="oba"){

    $data['rezultat']=  $this->prijava_model->zgrabi_tabelu($tabela,$pol,$student);
    $data['tabela']=$tabela;
    $data['pol']=$pol;
    $data['student']=$student;

    $prijavljen = $this->session->userdata('prijavljen');
    if($prijavljen)
    {
        $this->load->view('prijava/trust.php', $data);  
    }
    else
    {
        redirect('login');
    }
}

Further you will notice that it uses Prijava_model model's zgrabi_tabelu function:

function zgrabi_tabelu($tabela,$pol,$student){
    $upit_rezultat=array();

    if($pol=="oba" && $student="oba")
        $upit = $this->db->get($tabela);
    else if($pol!="oba" && $student!="oba")
        $upit=$this->db->get_where($tabela,array('pol'=>$pol,'stari_novi_student'=>$student));
    else if($pol!="oba" && $student=="oba")
        $upit=$this->db->get_where($tabela, array('pol'=>$pol));
    else if( $pol=="oba" && $student!="oba")
        ;//$upit=$this->db->get_where($tabela, array('stari_novi_student'=>$student));

    foreach($upit->result() as $red){
        array_push($upit_rezultat, $red);
    }

    return $upit_rezultat;
}

And I think that here in the model's zgrabi_tabelu function lies problem as every possible combination works fine, except for the last one, when I try to grab data by changing only last selection menu Izaberite studente: leaving all other options intact:

doesn't work1 && doesn't work2 WILL NOT WORK

but when I change previous field Izaberite pol: to anything beside Oba it will work fine:

works

And lastly let me provide you with HTML of menu items:

<div>
    <label>Izaberite kurs:</label>
    <select class="kurs" id="kurs_datum">
        <option value="letnji" selected='selected'>Letnji kurs(27.6 - 7.7.2012)</option>
        <option value="jesenji" >Jesenji kurs(10.10 - 21.10.2012)</option>
    </select>
</div>
<div>   
    <label>Izaberite pol:</label>
    <select class="filter" id="pol">
        <option value="oba" selected='selected'>Oba</option>
        <option value="zenski" >Ženski</option>
        <option value="muski" >Muški</option>
    </select>
</div>
<div>
    <label>Izaberite studente:</label>
    <select class="filter" id="student">
        <option value="oba" selected='selected'>Oba</option>
        <option value="novi" >Novi</option>
        <option value="stari" >Stari</option>
    </select>
</div>

Hope this makes sense. I will gladly clarify this further if necessary.
Any help appreciated.

2
  • 1
    when you say not work, what do you mean? what is the response in the network tab/firebug? is the ajax not working or is it a problem with your server side code? Commented Apr 3, 2012 at 20:32
  • I mean that when I choose any of those 2 combination on above images output doesn't update, even though page controller's function gets executed and page loaded, so I think it is something wrong with the logic inside model's zgrabi_tabelu function but I cannot see what.. Thanks Commented Apr 3, 2012 at 21:33

3 Answers 3

2

In your jquery call to open a new window, i think you want to remove that comma and put a slash there

so change this:

window.open("http://vipassana-srbija.comli.com/index.php/login/trust/"+str,"_self");

to:

window.open("http://vipassana-srbija.comli.com/index.php/login/trust/"+str+"/_self");
Sign up to request clarification or add additional context in comments.

2 Comments

I don't see how that can be problem if it works for any other combination beside those two I listed above??? Am I missing something here?? Thanks
Well, he is right, its correct to change this, but it wont break anything if it isnt corrected.
1
function zgrabi_tabelu($tabela,$pol,$student){
$upit_rezultat=array();

if($pol=="oba" && $student="oba")
    $upit = $this->db->get($tabela);
else if($pol!="oba" && $student!="oba")
    $upit=$this->db->get_where($tabela,array('pol'=>$pol,'stari_novi_student'=>$student));
else if($pol!="oba" && $student=="oba")
    $upit=$this->db->get_where($tabela, array('pol'=>$pol));
else if( $pol=="oba" && $student!="oba")
    ;//$upit=$this->db->get_where($tabela, array('stari_novi_student'=>$student));

foreach($upit->result() as $red){
    array_push($upit_rezultat, $red);
}

return $upit_rezultat;
}

You left out a = on the first line...

if($pol=="oba" && $student="oba")

should be

if($pol=="oba" && $student=="oba")

I believe the IF function will return false because its a false operator.

1 Comment

Yes!!! That's all I needed, Eagle's eyes!!! Thanks for looking into it my friend.
0

An additional note, where you're calling your view '$this->load->view('prijava/trust.php', $data);' - should trust.php not be just trust - CI adds .php to the end when 'requiring' in views.

2 Comments

It doesn't matter either way. With or without the .php it will use the same file. At least with code igniter 2.x.
Merely an observation, I don't put .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.