gpt4 book ai didi

php - 无法将数据从数据库读取到下拉列表中

转载 作者:行者123 更新时间:2023-11-29 18:47:41 25 4
gpt4 key购买 nike

我正在尝试从数据库读取数据。我无法从数据库加载部分并在相关多选下拉列表中插入部分。

我的观点(drop_view):

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.13/js/bootstrap-multiselect.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.13/css/bootstrap-multiselect.css" />
<script src="jquery-ui-multiselect-widget-master/src/jquery.multiselect.js"></script>
<link rel="stylesheet" href="jquery-ui-multiselect-widget-master/jquery.multiselect.css" />
</head>
<script>
$(document).ready(function() {
$("#student").change(function() {
//alert($(this).val())
$.post("http://localhost/Dropdown/index.php/Drop_control/class", {
student: $(this).val()
}, function(data) {
$("#class").html(data);

});
});
});
</script>
<script>
$(document).ready(function() {
$("#class").change(function() {
//alert($(this).val())
$.post("http://localhost/Dropdown/index.php/Drop_control/section", {
class: $(this).val()
}, function(data) {
$("#section").html(data);

});
});
});
</script>
<body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/js/bootstrap.min.js"></script>
<link href="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/css/bootstrap-multiselect.css" rel="stylesheet" type="text/css" />
<script src="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/js/bootstrap-multiselect.js" type="text/javascript"></script>

<div id="mine">
</div>

<script type="text/javascript">
$(function() {
$('#section').multiselect({
includeSelectAllOption: false;
});
$('#btnSelected').click(function() {
var selected = $("#section option:selected");
var message = "";
selected.each(function() {
message += $(this).text() + " " + $(this).val() + "\n";
});
alert(message);
});
});
</script>
<script>
/*$(document).ready(function(){
$('#section').multiselect({
nonSelectedText: 'Select Section',
enableFiltering: true,
enableCaseInsensitiveFiltering: true,
//buttonWidth:'400px'
});

$('#table_frame').on('submit', function(event){
event.preventDefault();
var form_data = $(this).serialize();
$.ajax({
// url:"insert.php",
method:"POST",
data:form_data,
success:function(data)
{
$('#section option:selected').each(function(){
$(this).prop('selected', false);
});
$('#section').multiselect('refresh');
alert(data);
}
});
});


});*/
</script>


<table class="table table-bordered">
<tr>
<td>
<div align="center">Select CSV</div>
</td>
<td>
<div align="center">:</div>
</td>
<td>

<select name="selectcsv" id="student">
<option value="" selected="selected" >Select option</option>
<option value="AllStudents" >All Students</option>
<option value="Select_Specfic_class">Select_Specfic_class</option>
</select>
</td>
</tr>

<tr>
<td>
<div align="center">Class</div>
</td>
<td>
<div align="center">:</div>
</td>
<td>
<select name="class" id="class">
<option selected="selected">Select Class</option>
</select>
</td>
</tr>

<tr>
<td>
<div align="center">Section</div>
</td>
<td>
<div align="center">:</div>
</td>
<td id="table_frame">
<select id="section" multiple="multiple">
<option selected="selected">Select Section</option>
</select>//here i am getting problem
</td>
</tr>

</table>

</body>

</html>

我的模型(drop_model):

<?php 

class Drop_model extends CI_Model
{
function __constuct()
{
parent::__constuct();
}
public function class1()
{
$this->db->select('class');
$this->db->distinct();
$res=$this->db->get('student_details');
return $res->result();
}

public function section1($class)
{
$this->db->select('section');

$this->db->where('class',$class);
$this->db->distinct();
$res=$this->db->get('student_details');
return $res->result();
}
}

我的 Controller (Drop_control):

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

class Drop_control extends CI_Controller
{

public function index()
{
$this->load->view('drop_view');
}
public function class()
{
$student=$this->input->post('student');

$this->load->model('drop_model');
$user=$this->drop_model->class1();
print_r($user);

echo '<option value="" selected="selected">Select class</option>';
foreach($user as $c){

echo '<option value="'.$c->class.'">'.$c->class.'</option>';
}



}
public function section()
{
$class=$this->input->post('class');

$this->load->model('drop_model');
$usr=$this->drop_model->section1($class);


foreach($usr as $s){

echo '<option value="'.$s->section.'">'.$s->section.'</option>';

}



}
}
?>

最佳答案

在以下版本 (<-5.6.x) 中,您不能使用名称作为函数名称。请参阅this 。另外,从 Controller 的类中删除 print_r($user);

关于php - 无法将数据从数据库读取到下拉列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44515683/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com