codeigniter中的数组问题 [英] Array issue in codeigniter

查看:55
本文介绍了codeigniter中的数组问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个桌子爱好,因为我拿了一个名为hid []的数组。

因为我通过了hid和hnm。

我有另一个桌子员工和我把隐藏作为外键。

当我从前端传递隐藏时:

hid:

[0] - > 1

[1] - > 2

[2] - > 3

当我从前端传递hnm时:

[0] - >阅读

[1] - >游泳

[2] - >跳舞



代码:

控制器代码:

<?php 
/ **
*
* /
类员工扩展CI_Controller
{

公共职能__construct()
{
#code ...
parent :: __ construct();
$ this-> load-> database();
$ this-> load-> model('Employee_model');
$ this-> load-> helper('url');
}
//保存数据
公共功能add()
{
$ data ['data'] = $ this-> Employee_model-> display_records( );

$ data ['ctr_id'] = $ this-> db-> select(*) - > from('country') - > get() - > result ();
$ data ['st_id'] = $ this-> db-> select(*) - > from('state') - > get() - > result();
$ data ['ct_id'] = $ this-> db-> select(*) - > from('city') - > get() - > result();
$ data ['hid'] = $ this-> db-> select(*) - > from('hobby') - > get() - > result();
$ data ['mid'] = $ this-> db-> select(*) - > from('meal_preference') - > get() - > result();
$ data ['pid'] = $ this-> db-> select(*) - > from('payment_mode') - > get() - > result();
/ * echo< pre>;
print_r($ _ POST);
die; * /
返回$ this-> load-> view('employee_add',$ data);
}

公共函数save()
{
$ efname = $ this-> input-> post('efname');
$ elname = $ this-> input-> post('elname');
$ ecompany = $ this-> input-> post('ecompany');
$ eadd = $ this-> input-> post('eadd');
$ ctr_id = $ this-> input-> post('ctr_id');
$ st_id = $ this-> input-> post('st_id');
$ ct_id = $ this-> input-> post('ct_id');
$ email = $ this-> input-> post('email');
$ emobile = $ this-> input-> post('emobile');

$ hid = json_encode($ this-> input-> post('hid'));

$ oidVal = implode(,,$ this-> input-> post('hid'));

$ data = array('oidVal'=> $ oidVal);
echo< pre>;的print_r($ _ POST);模具;
$ mid = $ this-> input-> post('mid');
$ pid = $ this-> input-> post('pid');
$ output = $ this-> Employee_model-> saverecords($ efname,$ elname,$ ecompany,$ eadd,$ ctr_id,$ st_id,$ ct_id,$ email,$ emobile,$ hid,$ oidVal ,$中旬,$ PID);
redirect('Employee / display');
echo员工记录保存成功.. !!;
}
公共功能显示()
{
$ data ['employee'] = $ this-> Employee_model-> display_records();
$ data ['hobby'] = $ this-> Employee_model-> display_hobby();
// echo< pre>; print_r($ data); die;
$ this-> load-> view('employee_view',$ data);

}
公共功能编辑($ id)
{

$ data ['employee'] = $ this-> Employee_model-> displayrecordsById($ ID);

$ data ['ctr_id'] = $ this-> db-> select(*) - > from('country') - > get() - > result ();
$ data ['st_id'] = $ this-> db-> select(*) - > from('state') - > get() - > result();
$ data ['ct_id'] = $ this-> db-> select(*) - > from('city') - > get() - > result();
$ data ['hid'] = $ this-> db-> select(*) - > from('hobby') - > get() - > result();
$ data ['mid'] = $ this-> db-> select(*) - > from('meal_preference') - > get() - > result();
$ data ['pid'] = $ this-> db-> select(*) - > from('payment_mode') - > get() - > result();

返回$ this-> load-> view('employee_edit',$ data);
}
公共功能更新($ id)
{
$ efname = $ this-> input-> post('efname');
$ elname = $ this-> input-> post('elname');
$ ecompany = $ this-> input-> post('ecompany');
$ eadd = $ this-> input-> post('eadd');
$ ctr_id = $ this-> input-> post('ctr_id');
$ st_id = $ this-> input-> post('st_id');
$ ct_id = $ this-> input-> post('ct_id');
$ email = $ this-> input-> post('email');
$ emobile = $ this-> input-> post('emobile');

$ hid = json_encode($ this-> input-> post('hid'));
$ oidVal = implode(,,$ this-> input-> post('hid'));
$ data = array('oidVal'=> $ oidVal);
$ mid = $ this-> input-> post('mid');
$ pid = $ this-> input-> post('pid');

$ output = $ this-> Employee_model-> update_records($ id,$ efname,$ elname,$ ecompany,$ eadd,$ ctr_id,$ st_id,$ ct_id,$ email,$ EMOBILE,$藏,$ oidVal,$中旬,$ PID);
/ * echo< pre>;
print_r($ _ POST);
die; * /
redirect('Employee / display');
echo员工记录已成功更新.. !!;
}
公共功能删除($ id)
{
$ this-> Employee_model-> deleterecords($ id);
redirect('Employee / display');
echo记录删除成功!;
}
}
?>





型号:

<?php 
/ **
*
* /
类Employee_model扩展CI_Model
{
function __construct()
{
parent :: __ construct();
}

函数saverecords($ efname,$ elname,$ ecompany,$ eadd,$ ctr_id,$ st_id,$ ct_id,$ email,$ emobile,$ hid,$ oidVal,$ mid,$ pid)
{
#code ...
$ this-> db-> set('efname',$ efname);
$ this-> db-> set('elname',$ elname);
$ this-> db-> set('ecompany',$ ecompany);
$ this-> db-> set('eadd',$ eadd);
$ this-> db-> set('ctr_id',$ ctr_id);
$ this-> db-> set('st_id',$ st_id);
$ this-> db-> set('ct_id',$ ct_id);
$ this-> db-> set('email',$ email);
$ this-> db-> set('emobile',$ emobile);
$ this-> db-> set('hid',$ hid);
$ this-> db-> set('oidVal',$ oidVal);
$ this-> db-> set('mid',$ mid);
$ this-> db-> set('pid',$ pid);
$ this-> db-> insert('employee');
}
函数display_records()
{
$ query = $ this-> db-> select('employee.eid,employee.efname,employee.elname,employee .ecompany,employee.eadd,country.ctr_nm,state.st_nm,city.ct_nm,employee.email,employee.emobile,hobby.hnm,employee.oidVal,meal_preference.mnm,payment_mode.pnm');
$ this-> db-> from('employee');
$ this-> db-> join('country','employee.ctr_id = country.ctr_id','LEFT');
$ this-> db-> join('state','employee.st_id = state.st_id','LEFT');
$ this-> db-> join('city','employee.ct_id = city.ct_id','LEFT');
$ this-> db-> join('hobby','employee.hid = hobby.hid','LEFT');
$ this-> db-> join('meal_preference','employee.mid = meal_preference.mid','LEFT');
$ this-> db-> join('payment_mode','employee.pid = payment_mode.pid','LEFT');
// $ this-> db-> where('pid',$ pid);
$ query = $ this-> db-> get();
返回$ query-> result();
}
函数display_hobby()
{
$ query = $ this-> db-> select('hobby.hid,hobby.hnm');
$ this-> db-> from('hobby');
$ query = $ this-> db-> get();
返回$ query-> result();
}
函数displayrecordsById($ eid)
{
$ this-> db-> select('*');
$ this-> db-> from('employee');
$ this-> db-> join('country','employee.ctr_id = country.ctr_id','LEFT');
$ this-> db-> join('state','employee.st_id = state.st_id','LEFT');
$ this-> db-> join('city','employee.ct_id = city.ct_id','LEFT');
$ this-> db-> join('hobby','employee.hid = hobby.hid','LEFT');
$ this-> db-> join('meal_preference','employee.mid = meal_preference.mid','LEFT');
$ this-> db-> join('payment_mode','employee.pid = payment_mode.pid','LEFT');
$ this-> db-> where('eid',$ eid);
$ query = $ this-> db-> get();
返回$ query-> row();
}
//更新
函数update_records($ eid,$ efname,$ elname,$ ecompany,$ eadd,$ ctr_id,$ st_id,$ ct_id,$ email,$ emobile,$ hid,$ oidVal,$ mid,$ pid)
{
$ data = array

'efname'=> $ efname,
'elname'= > $ elname,
'ecompany'=> $ ecompany,
'eadd'=> $ eadd,
'ctr_id'=> $ ctr_id,
'st_id '=> $ st_id,
'ct_id'=> $ ct_id,
'电子邮件'=> $ email,
'emobile'=> $ emobile,
'hid'=> $ hid,
'oidVal'=> $ oidVal,
'mid'=> $ mid,
'pid'=> $ pid,
);

$ this-> db-> where('eid',$ eid);
$ this-> db-> update('employee',$ data);
}

//删除
函数deleterecords($ eid)
{
$ this-> db-> where('eid', $ EID);
$ this-> db-> delete('employee');
}

}
?>





添加员工(添加记录)代码:

<?php 
定义('BASEPATH')或退出('不允许直接访问脚本');
?><!DOCTYPE html>
< html lang =en>
< head>
< meta charset =utf-8>
< title>欢迎使用CodeIgniter< / title>

< style type =text / css>

:: selection {background-color:#E13300;白颜色; }
:: - moz-selection {background-color:#E13300;白颜色; }

body {
background-color:#fff;
保证金:40px;
字体:13px / 20px正常Helvetica,Arial,sans-serif;
颜色:#4F5155;
}

a {
颜色:#003399;
background-color:transparent;
font-weight:normal;
}

h1 {
颜色:#444;
background-color:transparent;
border-bottom:1px solid#D0D0D0;
字体大小:19px;
font-weight:normal;
保证金:0 0 14px 0;
填充:14px 15px 10px 15px;
}

代码{
font-family:Consolas,Monaco,Courier New,Courier,monospace;
字体大小:12px;
background-color:#f9f9f9;
border:1px solid#D0D0D0;
颜色:#002166;
display:block;
保证金:14px 0 14px 0;
填充:12px 10px 12px 10px;
}

#body {
保证金:0 15px 0 15px;
}

p.footer {
text-align:right;
字体大小:11px;
border-top:1px solid#D0D0D0;
行高:32px;
填充:0 10px 0 10px;
保证金:20px 0 0 0;
}

#container {
margin:10px;
border:1px solid#D0D0D0;
box-shadow:0 0 8px#D0D0D0;
}
< / style>
< / head>
< body>

< h2>添加员工< / h2>

< form method =postaction =save>
< table width =600border =1cellspacing =5cellpadding =5>

< tr>
< td width =230>输入名字< / td>
< td width =329>< input type =textname =efname>< / td>
< / tr>
< tr>
< td width =230>输入姓氏< / td>
< td width =329>< input type =textname =elname>< / td>
< / tr>
< tr>
< td width =230>输入公司< / td>
< td width =329>< input type =textname =ecompany>< / td>
< / tr>
< tr>
< td width =230>输入Adrress< / td>
< td width =329>< input type =textname =eadd>< / td>
< / tr>
< tr>
< td width =230>选择国家< / td>
< td>
< select name =ctr_id>
<?php foreach($ ctr_id as $ key => $ value):?>
< option value =<?php echo $ value-> ctr_id?>><?php echo $ value-> ctr_nm; ?>< /选项>
<?php endforeach; ?>
< / select>
< / td>
< / tr>
< tr>
< td width =230>选择州< / td>
< td>

< select name =st_id>
<?php foreach($ st_id as $ key => $ value):?>
< option value =<?php echo $ value-> st_id?>><?php echo $ value-> st_nm; ?>< /选项>
<?php endforeach; ?>
< / select>
< / td>
< / tr>
< tr>
< td width =230>选择城市< / td>
< td>

< select name =ct_id>
<?php foreach($ ct_id as $ key => $ value):?>
< option value =<?php echo $ value-> ct_id?>><?php echo $ value-> ct_nm; ?>< /选项>
<?php endforeach; ?>
< / select>
< / td>
< / tr>
< tr>
< td width =230>输入电子邮件< / td>
< td width =329>< input type =emailname =email>< / td>
< / tr>
< tr>
< td width =230>输入手机号码< / td>
< td width =329>< input type =textname =emobile>< / td>
< / tr>
< tr>
< td width =230>输入Hobby< / td>
< td>
<?php foreach($ hid as $ key => $ value):?>
< input type =checkboxname =hid []
value =<?php echo $ value-> hid;?>><?php echo $值 - > HNM;?>
<?php endforeach; ?>
< / td>
< / tr>
< tr>
< td width =230>输入膳食偏好< / td>
< td>
< select name =mid>
<?php foreach($ mid as $ key => $ value):?>
< option value =<?php echo $ value-> mid?>><?php echo $ value-> mnm; ?>< /选项>
<?php endforeach; ?>
< / select>
< / td>
< / tr>
< tr>
< td width =230>进入付款方式< / td>
< td>
<?php foreach($ pid as $ key => $ value):?>
< input type =radioname =pid
value =<?php echo $ value-> pid?>><?php echo $ value-> ; PNM; ?>
<?php endforeach; ?>
< / td>
< / tr>
< tr>
< td colspan =2align =center>< input type =submitname =save/>< / td>
< / tr>
< / table>
< / form>
< / body>
< / html>





我尝试过:



我使用了Implode和Explode,因为hid是一个数组。 
保存此数据后,我只能看到hid或hnm到视图屏幕。
我想将hid存储到我的数据库,hnm来查看屏幕。
帮我解决这个问题。

解决方案

this-> load-> database();


这 - >负载>模型( 'Employee_model');

这 - >负载>辅助( 'URL');
}
//保存数据
公共函数add()
{


I made a table hobby, in that i took an array named hid[].
In that i passed hid and hnm.
I have another table employee and I take hid as an foreign key.
When I passes the hid from front end as :
hid :
[0] -> 1
[1] -> 2
[2] -> 3
When I passes the hnm from front end as :
[0] -> Reading
[1] -> Swimming
[2] -> Dancing

Code :
Controller code :

<?php
/**
 * 
 */
class Employee extends CI_Controller
{
	
	public function __construct()
	{
		# code...
		parent::__construct();
		$this->load->database();
		$this->load->model('Employee_model');
		$this->load->helper('url');		
	}
	//save data
	public function add()
	{
		$data['data']=$this->Employee_model->display_records();

		$data['ctr_id'] = $this->db->select("*")->from('country')->get()->result();
		$data['st_id'] = $this->db->select("*")->from('state')->get()->result();
		$data['ct_id'] = $this->db->select("*")->from('city')->get()->result();
		$data['hid'] = $this->db->select("*")->from('hobby')->get()->result();
		$data['mid'] = $this->db->select("*")->from('meal_preference')->get()->result();
		$data['pid'] = $this->db->select("*")->from('payment_mode')->get()->result();
		/*echo "<pre>";
		print_r($_POST);
		die;*/
		return $this->load->view('employee_add',$data);
	}

	public function save()
	{		
			$efname=$this->input->post('efname');
			$elname=$this->input->post('elname');
			$ecompany=$this->input->post('ecompany');
			$eadd=$this->input->post('eadd');
			$ctr_id=$this->input->post('ctr_id');
			$st_id=$this->input->post('st_id');
			$ct_id=$this->input->post('ct_id');
			$email=$this->input->post('email');
			$emobile=$this->input->post('emobile');
			
			$hid=json_encode($this->input->post('hid'));

			$oidVal = implode(", ", $this->input->post('hid'));
			
			$data = array('oidVal' => $oidVal);
			echo "<pre>"; print_r($_POST);die; 
			$mid=$this->input->post('mid');
			$pid=$this->input->post('pid');
			$output = $this->Employee_model->saverecords($efname,$elname,$ecompany,$eadd,$ctr_id,$st_id,$ct_id,$email,$emobile,$hid,$oidVal,$mid,$pid);
			redirect('Employee/display');
			echo "Employee records saved successfully..!!";
	}		
	public function display()
	{
		$data['employee']=$this->Employee_model->display_records();
		$data['hobby']=$this->Employee_model->display_hobby();
		//echo "<pre>";print_r($data);die;
		$this->load->view('employee_view',$data);
		
	}
	public function edit($id)
	{	
		
		$data['employee']=$this->Employee_model->displayrecordsById($id);
		
		$data['ctr_id'] = $this->db->select("*")->from('country')->get()->result();
		$data['st_id'] = $this->db->select("*")->from('state')->get()->result();
		$data['ct_id'] = $this->db->select("*")->from('city')->get()->result();
		$data['hid'] = $this->db->select("*")->from('hobby')->get()->result();
		$data['mid'] = $this->db->select("*")->from('meal_preference')->get()->result();
		$data['pid'] = $this->db->select("*")->from('payment_mode')->get()->result();
		
		return $this->load->view('employee_edit',$data);
	}
	public function update($id)
	{
			$efname=$this->input->post('efname');
			$elname=$this->input->post('elname');
			$ecompany=$this->input->post('ecompany');
			$eadd=$this->input->post('eadd');
			$ctr_id=$this->input->post('ctr_id');
			$st_id=$this->input->post('st_id');
			$ct_id=$this->input->post('ct_id');
			$email=$this->input->post('email');
			$emobile=$this->input->post('emobile');
			
			$hid=json_encode($this->input->post('hid'));
			$oidVal = implode(", ", $this->input->post('hid'));
			$data = array('oidVal' => $oidVal);
			$mid=$this->input->post('mid');
			$pid=$this->input->post('pid');
			
			$output = $this->Employee_model->update_records($id,$efname,$elname,$ecompany,$eadd,$ctr_id,$st_id,$ct_id,$email,$emobile,$hid,$oidVal,$mid,$pid);
			/*echo "<pre>";
			print_r($_POST);
			die;*/
			redirect('Employee/display');
			echo "Employee records Updated successfully..!!";
	}
	public function delete($id)
	{
		$this->Employee_model->deleterecords($id);
		redirect('Employee/display');
		echo "Record deleted successfully !";
	}
}																										
?>



Model Code :

<?php
/**
 * 
 */
class Employee_model extends CI_Model
{
	function __construct()
	{
		parent::__construct();
	}
	
	function saverecords($efname,$elname,$ecompany,$eadd,$ctr_id,$st_id,$ct_id,$email,$emobile,$hid,$oidVal,$mid,$pid)
	{
		# code...
		$this->db->set('efname',$efname);
		$this->db->set('elname',$elname);
		$this->db->set('ecompany',$ecompany);
		$this->db->set('eadd',$eadd);
		$this->db->set('ctr_id',$ctr_id);
		$this->db->set('st_id',$st_id);
		$this->db->set('ct_id',$ct_id);
		$this->db->set('email',$email);
		$this->db->set('emobile',$emobile);
		$this->db->set('hid',$hid);	
		$this->db->set('oidVal',$oidVal);
		$this->db->set('mid',$mid);
		$this->db->set('pid',$pid);
		$this->db->insert('employee');
	}
	function display_records()
	{
		$query = $this->db->select('employee.eid,employee.efname,employee.elname,employee.ecompany,employee.eadd,country.ctr_nm,state.st_nm,city.ct_nm,employee.email,employee.emobile,hobby.hnm,employee.oidVal,meal_preference.mnm,payment_mode.pnm');
		$this->db->from('employee');
	  	$this->db->join('country', 'employee.ctr_id = country.ctr_id','LEFT');
	  	$this->db->join('state', 'employee.st_id = state.st_id','LEFT');
	  	$this->db->join('city', 'employee.ct_id = city.ct_id','LEFT');
	  	$this->db->join('hobby', 'employee.hid = hobby.hid','LEFT');
	  	$this->db->join('meal_preference', 'employee.mid = meal_preference.mid','LEFT');
	  	$this->db->join('payment_mode', 'employee.pid = payment_mode.pid','LEFT');
        // $this->db->where('pid',$pid);
      	$query=$this->db->get();
		return $query->result();
	}
	function display_hobby()
	{
		$query = $this->db->select('hobby.hid,hobby.hnm');
		$this->db->from('hobby');
		$query=$this->db->get();
		return $query->result();	
	}
	function displayrecordsById($eid)
	{
		$this->db->select('*');
		$this->db->from('employee');
	    $this->db->join('country', 'employee.ctr_id = country.ctr_id','LEFT');
	  	$this->db->join('state', 'employee.st_id = state.st_id','LEFT');
	  	$this->db->join('city', 'employee.ct_id = city.ct_id','LEFT');
	  	$this->db->join('hobby', 'employee.hid = hobby.hid','LEFT');
	  	$this->db->join('meal_preference', 'employee.mid = meal_preference.mid','LEFT');
	  	$this->db->join('payment_mode', 'employee.pid = payment_mode.pid','LEFT');
        $this->db->where('eid',$eid);
        $query=$this->db->get();
		return $query->row();
	}
	//Update
	function update_records($eid,$efname,$elname,$ecompany,$eadd,$ctr_id,$st_id,$ct_id,$email,$emobile,$hid,$oidVal,$mid,$pid)
	{
		$data = array
		(
	        'efname' => $efname,
	        'elname' => $elname,
	        'ecompany' => $ecompany,
	        'eadd' => $eadd,
	        'ctr_id' => $ctr_id,
	        'st_id' => $st_id,
	        'ct_id' => $ct_id,
	        'email' => $email,
	        'emobile' => $emobile,
	        'hid' => $hid,
	        'oidVal' => $oidVal,
	        'mid' => $mid,
	        'pid' => $pid,
	    );

		$this->db->where('eid', $eid);
		$this->db->update('employee', $data);
	}	

	//Delete
	function deleterecords($eid)
	{
		$this->db->where('eid', $eid);
		$this->db->delete('employee');
	}

}
?> 



Add Employee(Add record) code :

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>Welcome to CodeIgniter</title>

	<style type="text/css">

	::selection { background-color: #E13300; color: white; }
	::-moz-selection { background-color: #E13300; color: white; }

	body {
		background-color: #fff;
		margin: 40px;
		font: 13px/20px normal Helvetica, Arial, sans-serif;
		color: #4F5155;
	}

	a {
		color: #003399;
		background-color: transparent;
		font-weight: normal;
	}

	h1 {
		color: #444;
		background-color: transparent;
		border-bottom: 1px solid #D0D0D0;
		font-size: 19px;
		font-weight: normal;
		margin: 0 0 14px 0;
		padding: 14px 15px 10px 15px;
	}

	code {
		font-family: Consolas, Monaco, Courier New, Courier, monospace;
		font-size: 12px;
		background-color: #f9f9f9;
		border: 1px solid #D0D0D0;
		color: #002166;
		display: block;
		margin: 14px 0 14px 0;
		padding: 12px 10px 12px 10px;
	}

	#body {
		margin: 0 15px 0 15px;
	}

	p.footer {
		text-align: right;
		font-size: 11px;
		border-top: 1px solid #D0D0D0;
		line-height: 32px;
		padding: 0 10px 0 10px;
		margin: 20px 0 0 0;
	}

	#container {
		margin: 10px;
		border: 1px solid #D0D0D0;
		box-shadow: 0 0 8px #D0D0D0;
	}
	</style>
</head>
<body>

<h2>Add Employees</h2>

	<form method="post" action="save">
	<table width="600" border="1" cellspacing="5" cellpadding="5">
		
		<tr>
			<td width="230">Enter First Name </td>
			<td width="329"><input type="text" name="efname"></td>
		</tr>
		<tr>
			<td width="230">Enter Last Name </td>
			<td width="329"><input type="text" name="elname"></td>
		</tr>
		<tr>
			<td width="230">Enter Company </td>
			<td width="329"><input type="text" name="ecompany"></td>
		</tr>
		<tr>
			<td width="230">Enter Adrress </td>
			<td width="329"><input type="text" name="eadd"></td>
		</tr>
		<tr>	
			<td width="230">Select Country </td>
			<td>
					<select name="ctr_id">
						<?php foreach ($ctr_id as $key => $value) : ?>
						<option value="<?php echo $value->ctr_id ?>"><?php echo $value->ctr_nm; ?></option>
			    		<?php  endforeach; ?>
					</select>
			</td>
		</tr>
		<tr>	
			<td width="230">Select State </td>
			<td>

				<select name="st_id">
						<?php foreach ($st_id as $key => $value) : ?>
						<option value="<?php echo $value->st_id ?>"><?php echo $value->st_nm; ?></option>
			    		<?php  endforeach; ?>
				</select>
			</td>
		</tr>
		<tr>	
			<td width="230">Select City </td>
			<td>

				<select name="ct_id">
						<?php foreach ($ct_id as $key => $value) : ?>
						<option value="<?php echo $value->ct_id ?>"><?php echo $value->ct_nm; ?></option>
			    		<?php  endforeach; ?>
					</select>
			</td>
		</tr>
		<tr>
			<td width="230">Enter Email </td>
			<td width="329"><input type="email" name="email"></td>
		</tr>
		<tr>
			<td width="230">Enter Mobile number </td>
			<td width="329"><input type="text" name="emobile"></td>
		</tr>
		<tr>
			<td width="230">Enter Hobby</td>
				<td>
					<?php foreach ($hid as $key => $value) : ?>
					<input type="checkbox" name="hid[]"
					value="<?php echo $value->hid; ?>"><?php echo $value->hnm;?>
					<?php  endforeach; ?>
				</td>
		</tr>
		<tr>	
			<td width="230"> Enter Meal Preference </td>
			<td>
					<select name="mid">
						<?php foreach ($mid as $key => $value) : ?>
						<option value="<?php echo $value->mid ?>"><?php echo $value->mnm; ?></option>
			    		<?php  endforeach; ?>
					</select>
			</td>
		</tr>
		<tr>
			<td width="230">Enter Payment Mode </td>
				<td>
						<?php foreach ($pid as $key => $value) : ?>
						<input type="radio" name="pid" 
						value="<?php echo $value->pid ?>"><?php echo $value->pnm; ?>
					<?php endforeach; ?> 
			</td>
		</tr>
		<tr>
			<td colspan="2" align="center"><input type="submit" name="save"/></td>
		</tr>
</table>
</form>
</body>
</html>



What I have tried:

I used Implode and Explode because hid is an array.
I can only see either hid or hnm to the view screen after save this data.
I want to store hid to my database and hnm to view screen.
help me with this.

解决方案

this->load->database();


this->load->model('Employee_model');


this->load->helper('url'); } //save data public function add() {


这篇关于codeigniter中的数组问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆