当通过下拉列表从列表中选择一个选项时,会在codeigniter中显示

时间:2015-03-21 05:21:44

标签: php codeigniter

我已将数据库中的数据显示为表格。在此表的顶部,我有listby和filterby下拉列表。当从codeigniter中的另一个listby下拉选项中选择一个来自list的选项时。

display.php(view)

<?php

    $con=mysqli_connect('localhost','root','','my_db');
    $sql="select * from feedback";
    $result=mysqli_query($con,$sql);
     ?>
    <html>
        <head>
            <script>
                function listby(str)
                            {
                            var xmlhttp;
                            if (window.XMLHttpRequest)
                              {
                              xmlhttp=new XMLHttpRequest();
                              }
                            else
                              {
                              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                              }

                            xmlhttp.onreadystatechange=function()
                              {
                              if (xmlhttp.readyState==4 && xmlhttp.status==200)
                                {
                                document.getElementById("mydiv").innerHTML=xmlhttp.responseText;
                                }
                              }
                            xmlhttp.open("GET","user1/ajax1?listby="+str,true);
                            xmlhttp.send();

                            }


                function filterby(str,limit)
                            {
                            var xmlhttp;
                            if (window.XMLHttpRequest)
                              {
                              xmlhttp=new XMLHttpRequest();
                              }
                            else
                              {
                              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                              }

                            xmlhttp.onreadystatechange=function()
                              {
                              if (xmlhttp.readyState==4 && xmlhttp.status==200)
                                {
                                document.getElementById("mydiv").innerHTML=xmlhttp.responseText;
                                }
                              }

                            xmlhttp.open("GET","user1/ajax2?filterby="+str+"&limit="+limit,true);
                            xmlhttp.send();
                            }




            </script>
        </head>
        <body>
                        <table >
                            <tr><td> List by:<select name="listby" id="select1" onchange="listby(this.value)">
                                    <option value="">select</option>
                                    <option value="5">5</option>
                                    <option value="10">10</option>
                                    <option value="20">20 </option>
                                    <option value="all">all </option>
                                    </select></td>

                                <td>    Filter by:<select name="filterby" onchange="filterby(this.value,document.getElementById('select1').value)">
                                    <option value="">select</option>
                                    <option value="php">php</option>
                                    <option value="dotnet">dotnet</option>
                                    <option value="java">java</option>
                                    <option value="seo">seo</option>
                                    </select></td>



                                <td><button>export to pdf </button></td>

                            </tr>
                        </table>    <br><br><br><br>



    <div id="mydiv">
    <table border="1" align="center" id="t1">

        <tr>

            <th>Sl.no</th>
            <th>Name</th>
            <th>Mobile</th>
            <th>Place</th>
            <th>Class</th>
            <th>Email</th>
            <th>College</th>
            <th>Technologies interested in</th>
            <th>Mobile Apps development</th>
            <th>Feedback</th>
            <th>interested to study latest technologies</th></tr>
    <?php
        while($row=mysqli_fetch_array($result))
        {
    ?>

     <tr>
        <td><?php echo $row['id'];?></td>
        <td><?php echo $row['name'];?></td>
        <td><?php echo $row['mobile'];?></td>
        <td><?php echo $row['place'];?></td>
        <td><?php echo $row['class'];?></td>
        <td><?php echo $row['email'];?></td>
        <td><?php echo $row['college'];?></td>
        <td><?php echo $row['technologies_interested_in'];?></td>
        <td><?php echo $row['mobile_apps_development'];?></td>
        <td><?php echo $row['feedback'];?></td>
        <td><?php echo $row['interested_to_study_latest_technologies'];?></td>


     </tr> 
     <?php  
            } 
     ?>

    </table>
    </div>
    </body>
    </html>

<!-- begin snippet: js hide: false -->

<!-- language: lang-js -->


    ajax1.php



    <table border=0>
        <tr>

            <th>Sl.no</th>
            <th>Name</th>
            <th>Mobile</th>
            <th>Place</th>
            <th>Class</th>
            <th>Email</th>
            <th>College</th>
            <th>Technologies interested in</th>
            <th>Mobile Apps development</th>
            <th>Feedback</th>
            <th>interested to study latest technologies</th></tr>


        <?php
             foreach($ajax1 as $row)
        {
        ?>
            <tr>
                <td><?php echo $row['id'];?></td>
                <td><?php echo $row['name'];?></td>
                <td><?php echo $row['mobile'];?></td>
                <td><?php echo $row['place'];?></td>
                <td><?php echo $row['class'];?></td>
                <td><?php echo $row['email'];?></td>
                <td><?php echo $row['college'];?></td>
                <td><?php echo $row['technologies_interested_in'];?></td>
                <td><?php echo $row['mobile_apps_development'];?></td>
                <td><?php echo $row['feedback'];?></td>
                <td><?php echo $row['interested_to_study_latest_technologies'];?></td>

            </tr> 




        <?php
        }
        ?>
    </table>


     ajax2.php   



        <table border=0>
        <tr>

            <th>Sl.no</th>
            <th>Name</th>
            <th>Mobile</th>
            <th>Place</th>
            <th>Class</th>
            <th>Email</th>
            <th>College</th>
            <th>Technologies interested in</th>
            <th>Mobile Apps development</th>
            <th>Feedback</th>
            <th>interested to study latest technologies</th>
        </tr>


        <?php
             foreach($ajax2 as $row)
        {
        ?>
            <tr>
                <td><?php echo $row['id'];?></td>
                <td><?php echo $row['name'];?></td>
                <td><?php echo $row['mobile'];?></td>
                <td><?php echo $row['place'];?></td>
                <td><?php echo $row['class'];?></td>
                <td><?php echo $row['email'];?></td>
                <td><?php echo $row['college'];?></td>
                <td><?php echo $row['technologies_interested_in'];?></td>
                <td><?php echo $row['mobile_apps_development'];?></td>
                <td><?php echo $row['feedback'];?></td>
                <td><?php echo $row['interested_to_study_latest_technologies'];?></td>

            </tr> 




        <?php
        }
        ?>
    </table>




<!-- language: lang-css -->

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

    class User_model1 extends CI_Model
        {
            public function __construct()
                {

                $this->load->database();
                }

            function get_student_details()
                {

                $query=$this->db->get('feedback');
                return $query->result_array();

                }

            function get_ajax1()
                {

                    $con=mysqli_connect('localhost','root','','my_db');
                    $listby=$_GET['listby'];
                    $sql="select * from feedback order by name asc limit ".$listby;
                    $query=mysqli_query($con,$sql);
                    return $query->result_array();
                }

            function get_ajax2()
                {

                        $con=mysqli_connect('localhost','root','','my_db');
                        $filterby=$_GET['filterby'];
                        $limit=$_GET['limit'];

                        if ($limit=="")
                            {
                            $sql="select * from feedback where technologies_interested_in='".$filterby."'";
                            }
                        else
                            {   
                            $sql="select * from feedback where technologies_interested_in='".$filterby."' limit ".$limit;
                            }

                        $query=mysqli_query($con,$sql);
                        return $query->result_array();
                }
        }
    ?>

0 个答案:

没有答案