在下面的代码中,当我在不检查任何值的情况下进行更新时,它会显示来自 db.And 的错误未定义变量:为 foreach() 在 113 和 119 处提供的记录和无效参数未定义变量:第 123 行中的行尝试获取非属性-student_detail_view 中 123 中的对象。
请任何人帮助我。
控制器 student_site:
function index()
{
$data = array();
if($query = $this->student_model->get_exam_data())
{
$data['exam_data'] = $query;
}
$this->load->view('student_view', $data);
}
function studentupdate()
{
$data = array();
$exam_name = $this->input->post('exam_name');
$course_name = $this->input->post('course_name');
if($query = $this->student_model->get_exam_data())
{
$data['exam_data'] = $query;
}
if($query = $this->student_model->get_records($exam_name))
{
$data['records'] = $query;
}
if($query = $this->student_model->get_course_code_records($exam_name))
{
$data['course_records'] = $query;
}
if($query = $this->student_model->get_all_coursesubject_records())
{
$data['all_coursesubject_records'] = $query;
}
$this->load->view('student_detail_view', $data);
}
function studentcreate()
{
$data = array();
$exam_name = $this->input->post('exam_name');
$data['exam_name'] = $exam_name;
/*if($query = $this->student_model->get_exam_data())
{
$data['exam_data'] = $query;
}*/
if($query = $this->student_model->get_course_code_records($exam_name)) //get unique records of coursecode from the coursesubject table
{
$data['course_records'] = $query;
}
/*if($query = $this->student_model->get_subject_code_records($exam_name)) //write seperate function to get the the subject codes frm the coursesubject table based on the selected course code.
{
$data['subject_records'] = $query;
} */
$this->load->view('student_update', $data);
}
function subject_records()
{
$data = array();
$exam_name = $this->input->post('exam_name');
$course_name = $this->input->post('course_name');
if($query = $this->student_model->get_subject_records($exam_name,$course_name))
{
$data['subject_records'] = $query;
}
$this->load->view('subject_view', $data);
}
function create_student()
{
/*$data = $this->input->post();
print_r($data);
var_dump($this->input->post());
$data=$this->input->post();*/
$j=1;
$createstudent = $this->input->post('createstudent');
if( $this->input->post('createstudent') != false ){
foreach($createstudent as $row_id)
{
$this->form_validation->set_rules("register_number_" . $row_id, "Register No", "required|min_length[2]");
//$this->form_validation->set_rules("name_". $row_id,"`Name`","required|xss_clean|min_length[1]");
}
}
if ($this->form_validation->run() == FALSE){
$data["message"]="";
$this->load->view("student_detail_view",$data);
//$this->load->view("master_data/view_master_data_footer");
}
while($j<=$this->uri->segment(3))
{
$data = array(
'exam_name' => $this->input->post('exam_name'),
'register_number' => $this->input->post('register_number_'.$j),
'name' => $this->input->post('name_'.$j),
'course_code' => $this->input->post('course_name_id'.$j),
'subject_code' => $this->input->post('subject_name'),
);
// $exam_name = mysql_real_escape_string($_POST["exam_name_id".$j]);//
$register_number=$this->input->post('register_number_'.$j);
if ($register_number != "")
{
$this->student_model->add_record($data);
}
$j++;
}
redirect('student_site', 'refresh');
}
function delete()
{
$this->student_model->delete_row();
redirect('student_site', 'refresh');
}
function manage_student()
{
$data['title']="Manage Student";
//query model to get data results for form
$data=array();
if($query=$this->student_model->get_student_records()){
$data['records']=$query;
}
$editstudent = $this->input->post('editstudent');
if( $this->input->post('editstudent') != false ){
foreach($editstudent as $row_id)
{
$this->form_validation->set_rules("register_number_" . $row_id, "register_number", "required|min_length[2]");
}
}
if ($this->form_validation->run() == FALSE){
$data["message"]="";
//$this->load->view("master_data/view_master_data_header",$data);
//$this->load->view("master_data/view_master_data_nav");
$this->load->view("student_detail_view",$data);
//$this->load->view("master_data/view_master_data_footer");
} else {
// single update - working
if( $this->input->post('editstudent') != false )
{
foreach ($editstudent as $row_id)
{
$data = array(
'register_number' => $this->input->post('register_number_'.$row_id),
'name' => $this->input->post('name_'.$row_id),
'course_code' => $this->input->post('course_code_id'.$row_id),
'subject_code' => $this->input->post('subject_code_id'.$row_id),
);
$this->student_model->update_student_records( $row_id, $data );
}
$this->session->set_flashdata('dbaction', 'Selected Records have been updated successfully');
redirect('student_site', 'refresh');
}
}
}
$data = array(
'exam_name' => $this->input->post('exam_name_id'),
'register_number' => $this->input->post('register_number'),
'name' => $this->input->post('name'),
'subject_code' => $this->input->post('subject_code'),
'course_code' => $this->input->post('course_code'),
);
$exam_name = $this->input->post('exam_name');
$register_number = $this->input->post('register_number');
$name = $this->input->post('name');
$course_code = $this->input->post('course_code');
$subject_code = $this->input->post('subject_code');
$this->student_model->update_student_record($exam_name,$register_number,$name,$course_code,$subject_code,$data);
$data = array();
$query = $this->student_model->get_records($exam_name);
echo "<pre>";
print_r($query);
exit;
if($query)
{
$data['records'] = $query;
}
$this->load->view('student_detail_view', $data);
function crud()
{
}
function deleting()
{
}
型号:student_model
function get_records($exam_name)
{
$this->db->where('exam_name',$exam_name);
$query = $this->db->get('student_table');
return $query->result();
}
function get_exam_data()
{
$this->db->distinct();
$this->db->select("CONCAT(exam_name, ' ', month,' ',year) AS fullexamname", FALSE);//this will concat the value
$query = $this->db->get('exam_table');
return $query->result();
}
function get_course_records($exam_name)
{
//echo "exam_name".$exam_name;
$this->db->select('exam_name,course_code');
$this->db->where('exam_name',$exam_name);
$query = $this->db->get('student_table');
return $query->result();
}
function get_subject_records($exam_name,$course_name)
{
//echo "exam_name inside get_subject_records".$exam_name;
$this->db->select('subject_code');
//$this->db->where('exam_name',$exam_name);
$this->db->where('course_code',$course_name);
$query = $this->db->get('coursesubject');
return $query->result();
}
function get_all_coursesubject_records()
{
//echo "exam_name inside get_subject_records".$exam_name;
$this->db->select('course_code');
$this->db->select('subject_code');
$query = $this->db->get('coursesubject');
return $query->result();
}
function get_course_code_records($course_name)
{
$query = $this->db->get('coursesubject');
return $query->result();
}
function get_subject_code_records()
{
$this->db->distinct();
$this->db->select('subject_code');
$query = $this->db->get('coursesubject');
return $query->result();
}
function update_student_record($exam_name,$register_number,$name,$course_code, $subject_code,$data)
{
echo "exam_name".$exam_name;
echo "register_number".$register_number;
echo "name".$name;
$this->db->where('exam_name',$exam_name);
$this->db->where('register_number',$register_number);
//$this->db->where('name',$name);
//$this->db->where('course_code',$course_code);
//$this->db->where('subject_code',$subject_code);
$this->db->update('student_table',$data);
}
查看:student_detail_view
<script type="text/javascript" src="<?php echo base_url();?>js/jquery.dataTables.js" ></script>
<script type="text/javascript" src="<?php echo base_url();?>js/jquery.dataTables.min.js" ></script>
<section id="tables">
<script>
jQuery(document).ready(function() {
oTable = jQuery('#studenttable').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers"
});
});
</script>
<script type="text/javascript" charset="utf-8">
function get_studentdetails() {
var exam_name = jQuery('#exam_name_id').val();
//alert("exam_name"+exam_name);
jQuery.ajax({
data: {
exam_name: exam_name,
},
type: 'POST',
url: 'student_site/studentupdate',
success: function(data){
//alert("inside change");
console.log(data);
jQuery('#details').html(data);
jquery('#deleting').html(data);
}
});
jQuery(document).ready(function(){
jQuery.ajax({
data: {
exam_name: exam_name,
},
type: 'POST',
url: 'student_site/studentcreate',
success: function(data){
//alert("inside change");
console.log(data);
jQuery('#crud').html(data);
jquery('#deleting').html(data);
}
});
});
}
function CheckBoxVerification(From)
{
alert('hai');
alert('hai:' $("table input[type=checkbox]:checked").length);
if(From == "Insert")
{
if(!!$('#rowInsert input:checked').length == false)
{
alert('please select at least one check box to Create ...!');
}
}
if(From == "Update")
{
if(!!$('#rowUpdate input:checked').length == false)
{
alert('please select at least one check box to Update ...!');
}
}
}
function get_subjectdetails() {
//var index = jQuery('#index').val();
var course_name = jQuery('#course_name_id').val();
//alert("course_name"+course_name);
//var exam_name = jQuery('#course_name_id>option:selected').text();
var exam_name = jQuery('#exam_name_id').val();
var ssubject_code = jQuery('#ssubject_code_id').val();
//var partsArray = exam_name.split('.');
//alert("ssubject_code"+ssubject_code);
//alert("course_name"+course_name);
//alert("exam_name"+exam_name);
jQuery.ajax({
data: 'exam_name='+exam_name+'&course_name=' + course_name,
type: 'POST',
url: 'student_site/subject_records',
success: function(data){
//alert("inside change");
console.log(data);
//alert ("data"+data);
//for(var j = course_name; j < ssubject_code; j++)
//{
jQuery('#ssubject_code').empty().append(data);
//}
}
});
}
</script>
<?php
$attributes=array(
'name'=>'updatecustomer',
'id'=>'updatecustomer'
);
echo form_open('student_site/manage_student',$attributes);
?>
<div id="validation_failed">
<?php
echo validation_errors();
?>
<?php $data = array();
foreach ($records as $row)
{
$data[$row->course_code] = $row->course_code;
}
$subject_data = array();
foreach ($records as $row)
{
$subject_data[$row->subject_code] = $row->subject_code;
}
var_dump($row->course_code );
?>
<div id="Processy">
<table class="display table table-bordered table-striped" id='studenttable'>
<thead>
<tr font style='font-size:13px'>
<th> </th>
<th> </th>
<th>Register Number</th>
<th>Name </th>
<th>Course Code</th>
<th>Subject Code</th>
</tr></thead>
<?php if(isset($records)) : foreach($records as $row) : ?>
<tr >
<td>
<?php echo anchor('student_site/delete/'.$row->id, 'Delete',array('onClick'=>"return confirm('Are you sure want to delete..?')")); ?>
</td>
<td id="rowUpdate">
<input type=checkbox name="editstudent[]" id="editstudent[]" value="<?php echo $row->id ?>">
</td>
<td ><input class="inputmedium span2" type="text" name="register_number_<?php echo $row->id ?>" id="register_number_<?php echo $row->id ?>" value="<?php echo $row->register_number; ?>" ></td>
<td ><input class="inputmedium span2" type="text" name="name_<?php echo $row->id ?>" id="name_<?php echo $row->id ?>" value="<?php echo $row->name; ?>" ></td>
<td >
<?php
$js = 'class="dropdown_class" id="course_code_id'.$row->id.'" onChange="get_subjectdetails()" ';
$js_name = 'course_code_id'.$row->id;
echo form_dropdown($js_name, $data, $row->course_code, $js);
?>
</td>
<td>
<?php
$js = 'class="dropdown_class" id="subject_code_id'.$row->id.'"';
$js_name = 'subject_code_id'.$row->id;
echo form_dropdown($js_name, $subject_data, $row->subject_code, $js);
?>
<div id="ssubject_code" ></div>
<input type="hidden" name="ssubject_code" id="ssubject_code" value="ssubject_code"/>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
<center>
<br /><input type="submit" class="btn-success btn" value="Update Student"></center>
<?php else : ?>
<h2>No records were returned.</h2>
<?php endif; ?>