0
저는보기 페이지에서 department
테이블의 드롭 다운을 채우는 CodeIgniter 응용 프로그램을 가지고 있습니다.한 테이블의 선택된 드롭 다운 값을 다른 테이블에 삽입하십시오.
dept_id int(11) PK
dept_name varchar(10)
내가 department
테이블에 다음 값이 :
여기 department
테이블의 구조이다 DEPT_NAME의
dept_id dept_name
1 EEE
2 CSE
3 ME
4 CE
5 ARCH
값은 내 드롭 다운에 채워됩니다.
내보기 파일 내 컨트롤러가 student.php
student_view.php
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My first site in CI</title>
</head>
<body>
<h2>Student Information</h2>
<form method="post" action="<?php echo base_url();?>index.php/student/insert_student_db">
<table width="800" border="0">
<th width="213" align="right" scope="row">Name:</th>
<td width="161"><input type="text" name="name" size="60" /></td>
</tr>
<tr>
<th align="right" scope="row">Roll:</th>
<td><input type="text" name="roll" size="60" /></td>
</tr>
<tr>
<th align="right" scope="row">Department:</th>
<td>
<select name="department">
<?php
$sql = mysql_query("SELECT dept_name FROM department");
while ($row = mysql_fetch_array($sql)){
echo "<option value=\"department1\">" . $row['dept_name'] . "</option>";
}
?>
</select>
</td>
</tr>
<tr>
<th align="right" scope="row">Email:</th>
<td><input type="text" name="email" size="60" /></td>
</tr>
<tr>
<th align="right" scope="row">Mobile:</th>
<td><input type="text" name="mobile" size="60" /></td>
</tr>
<tr>
<th align="right" scope="row"> </th>
<td><input type="submit" name="submit" value="Send" /></td>
</tr>
</table>
</form>
<table width="600" border="1" cellpadding="5">
<tr>
<th scope="col">Name</th>
<th scope="col">Roll</th>
<th scope="col">Department</th>
<th scope="col">Email</th>
<th scope="col">Mobile</th>
</tr>
<?php foreach ($student_list as $std_key){ ?>
<tr>
<td><?php echo $std_key->name; ?></td>
<td><?php echo $std_key->roll; ?></td>
<td><?php echo $std_key->department; ?></td>
<td><?php echo $std_key->email; ?></td>
<td><?php echo $std_key->mobile; ?></td>
</tr>
<?php }?>
</table>
</body>
</html>
입니다
<?php
if (! defined('BASEPATH')) exit('No direct script access allowed');
class Student extends CI_Controller
{
function __construct()
{
parent::__construct();
#$this->load->helper('url');
$this->load->model('student_model');
}
//Show all Students
public function index()
{
$data['student_list'] = $this->student_model->get_all_students();
$this->load->view('student_view', $data);
}
//Insert a student
public function insert_student_db()
{
$udata['name'] = $this->input->post('name');
$udata['roll'] = $this->input->post('roll');
$udata['department'] = $this->input->post('department');
$udata['email'] = $this->input->post('email');
$udata['mobile'] = $this->input->post('mobile');
$res = $this->student_model->insert_student($udata);
if($res)
{
header('location:'.base_url()."index.php/student/".$this->index());
}
}
}
?>
내 모델은 무엇 내가하고 싶은 것은 student_model.php
<?php
class Student_model extends CI_Model
{
function __construct()
{
parent::__construct();
$this->load->database();
}
//To retrieve all students
public function get_all_students()
{
$query = $this->db->get('student');
return $query->result();
}
//To add a new student to the database
public function insert_student($data)
{
return $this->db->insert('student', $data);
}
}
?>
이다 : 나는를 삽입 할 내 드롭 다운 목록에서 dept_name
값을 선택했습니다. 보기 페이지를 student
이라는 다른 표의 department
열에 내 모델 student_model.php
과 연결합니다. 그러나 삽입되는 값은 드롭 다운 값 대신 문자열 인 '부서'입니다. 내 코드에 어떤 문제가 있습니까? 이 과제하려면
name varchar(30)
roll varchar(10)
department varchar(10)
email varchar(50)
mobile varchar(15)
우수! 예상 한 출력을 얻었고'department'에 성공적으로'dept_name' 값을 삽입 할 수 있습니다. Muchos Gracias Senor Arbiza와 같은 빠르고 정확한 솔루션. :) –
하원 의원의 지시에 따르십시오. :) –