php - when selecting an option from listby another listby dropdown appers in codeigniter -
i have displayed data in database table.on top of table have listby , filterby dropdown. when selecting option listby listby dropdown appers in codeigniter.
display.php (view)
<?php $con=mysqli_connect('localhost','root','','my_db'); $sql="select * 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 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 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 study latest technologies</th></tr> <?php foreach($ajax1 $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 study latest technologies</th> </tr> <?php foreach($ajax2 $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 * feedback order 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 * feedback technologies_interested_in='".$filterby."'"; } else { $sql="select * feedback technologies_interested_in='".$filterby."' limit ".$limit; } $query=mysqli_query($con,$sql); return $query->result_array(); } } ?>
Comments
Post a Comment