• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dynamic Select Box

#1
Hello,
I have some time ago via Youtube (white the link no longer) a Dynamic Select Box, so the first field select the edition and in the second the Rare.
Unfortunately I get the $ slug not in this query purely.
Can someone help me there?

-----

Hallo,
ich habe vor einiger zeit via Youtube (Weiß den Link nicht mehr) ein Dynamisches Select Box eingebaut, so das im ersten Feld die Edition auswähle und im Zweiten die Rare.
Leider bekomme ich die $slug nicht in diese Abfrage rein.
Kann mir da jemand weiter helfen?



Script:
Code:
                $(document).ready(function(){
                   $('#add_edition2').on('change', function(){
                        var tb_edition_id = $(this).val();
                        if(tb_edition_id == '')
                        {
                            $('#add_rare2').prop('disabled', true);
                        }
                        else
                        {
                            $('#add_rare2').prop('disabled', false);
                            $.ajax({
                                // url:"<?php echo base_url() ?>karte/karten",
                                url:"<?php echo base_url() ?>karte/get_province",
                                type: "POST",
                                data: {'tb_edition_id' : tb_edition_id},
                                dataType: 'json',
                                success: function(data){
                                   $('#add_rare2').html(data);
                                },
                                error: function(){
                                    alert('Nix da...!!');
                                }
                            });
                        }
                   });
                });

Controller:
PHP Code:
            public function karten($slug)
                {
                    
// if (!$this->session->userdata('logged_in'))
                        // {
                            // redirect('users/login');
                        // }
                    
$data['get_karte'] = $this->Karte_model->get_karten($slug);
                    
$data['get_karte_sum'] = $this->Karte_model->get_karte_sumn($slug);
                    
$data['get_editions'] = $this->Karte_model->get_editions($slug);
                    
$this->load->view('templates/header');
                    
$this->load->view('karte/karten'$data);
                    
$this->load->view('templates/footer');
                }

            public function 
get_province($slug)
                {
                    
$tb_edition_id $this->input->post('tb_edition_id');
                    
$rares $this->Karte_model->get_province_query($tb_edition_id$slug);
                    if(
count($rares)>0)
                        {
                            
$pro_select_box '';
                            
$pro_select_box .= '<option value="">Rarität Auswählen</option>';
                            foreach (
$rares as $rare)
                                {
                                    
$pro_select_box .='<option value="'.$rare->tb_rare_id.'">'.$rare->tb_rare_name.'</option>';
                                }
                            echo 
json_encode($pro_select_box);
                        }
                } 

Model:
PHP Code:
            public function get_karten($slug false)
                {
                    
$this->db->join('db_ygo_karten_effekt''db_ygo_karten_effekt.tb_ygo_karten_effekt_id = db_ygo_karten_stats.tb_ygo_karten_stats_effekt');
                    
$this->db->join('db_ygo_karten_kategorie''db_ygo_karten_kategorie.tb_ygo_karten_kategorie_id = db_ygo_karten_stats.tb_ygo_karten_stats_kategorie');
                    
$query $this->db->get_where('db_ygo_karten_stats', array('tb_ygo_karten_stats_id' => $slug));
                    return 
$query->row_array();
                }

            public function 
get_editions($slug)
                {
                    
$this->db->select('*');
                    
$this->db->from('db_edition_stats');
                    
$this->db->join('db_edition''db_edition_stats.tb_edition_stats_edition = db_edition.tb_edition_id');
                    
$this->db->where('db_edition_stats.tb_edition_stats_karte'$slug);
                    
$this->db->order_by('tb_edition_kurzel''ASC');
                    
$query $this->db->get();
                    return 
$query->result();
                }

            public function 
get_province_query($get_editions$get_karten)
                {
                    
$this->db->join('db_rare''db_rare.tb_rare_id = db_edition_stats.tb_edition_stats_rare');
                    
$this->db->order_by('tb_edition_stats_nummer''ASC');
                    
$this->db->where('db_edition_stats.tb_edition_stats_karte'$get_karten);
                    
$query $this->db->get_where('db_edition_stats', array('tb_edition_stats_edition' => $get_editions));
                    return 
$query->result();
                } 

View:
Code:
            <div class="section">
                <h6 class="title-attr" style="margin-top:15px;" ><small>EDITION</small></h6>
                <div class="">
                    <select class="selectpicker dropdown-view" name="add_edition2" id="add_edition2">
                        <option value="">----</option>
<?php foreach($get_editions as $edition): ?>
                            <option value="<?php echo $edition->tb_edition_id; ?>"><?php echo $edition->tb_edition_kurzel; ?> - <?php echo $edition->tb_edition_name; ?></option>
<?php endforeach; ?>
                    </select>
                </div>
            </div>
            <div class="section" style="padding-bottom:5px;">
                <h6 class="title-attr"><small>Seltenheit</small></h6>
                <div>
                    <select class="selectpicker dropdown-view" name="add_rare2" id="add_rare2" disabled="">
                        <option value="">Rarität Auswählen</option>
                    </select>
                </div>
            </div>
Reply

#2
The controller functions that you're trying to call, expect a parameter $slug. So the url to call the function should look like this:
PHP Code:
site_url() . 'karte/get_province/' $slug

In your code, the function never gets that parameter when you do an AJAX request.
To solve this, pass the slug as one of the post data fields.

Code:
data: {'tb_edition_id' : tb_edition_id, 'slug' : slug },
Of course, you'll have to let your javascript fetch the value of slug.

Then, in the controller, simply read the value with $this->input->post('slug');
Reply

#3
The selection field remains disabled


Code:
            <script type="text/javascript">
                $(document).ready(function(){
                   $('#add_edition2').on('change', function(){
                        var tb_edition_id = $(this).val();
                        if(tb_edition_id == '')
                        {
                            $('#add_rare2').prop('disabled', true);
                        }
                        else
                        {
                            $('#add_rare2').prop('disabled', false);
                            $.ajax({
                                site_url() . 'karte/get_province/' . $slug;
                                // site_url() . '<?php echo base_url() ?>karte/get_province/' . $slug;
                                // url:"<?php echo base_url() ?>karte/get_province",
                                type: "POST",
                                data: {'tb_edition_id' : tb_edition_id, '$slug' : slug },
                                // data: {'tb_edition_id' : tb_edition_id},
                                dataType: 'json',
                                success: function(data){
                                   $('#add_rare2').html(data);
                                },
                                error: function(){
                                    alert('Nix da...!!');
                                }
                            });
                        }
                   });
                });
            </script>

PS.
Found the video now
https://www.youtube.com/watch?v=QTfPlTCsVME
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.