Array to string conversion on CodeIgniter - php

my problem is a want to insert multiple check box on my web application.
error Message
Array to string conversion
please help....
Controller :
public function add_overview_product($type)
{
if ($this->input->post('submit')) {
$type = $type;
$id_overview = $this->input->post('id_overview');
$records = array();
for ($i=0; $i < count($id_overview) ; $i++) {
$records[] = array(
'type' => $type,
'id_overview' => $id_overview[$i]
);
}
$check_idoverview = $this->Biostar->check_idoverview($type,$id_overview);
if ($check_idoverview > 0) {
$message = 'Sorry, The Product can not input twice with the same "TYPE" ';
} else {
foreach ($records as $key => $value) {
$datafield = array(
'type' => $type,
'id_overview' => $id_overview
);
$this->Biostar->saveoverviewproduct($datafield);
}
$data['type'] = $type;
$data['content'] = 'biostar/add_specification';
$this->load->view('dashboard/index', $data);
}
}
$data['diy'] = $diy;
$data['content'] = 'biostar/add_overview_product';
$this->load->view('dashboard/index', $data);
}
My : Model
public function saveoverviewproduct($datafield){
$sql = $this->db->insert('overview_biostar',$datafield);
return $sql;
}
public function check_idoverview($type,$id_overview){
$this->db->select('type');
$this->db->where('type',$type);
$this->db->where('id_overview',$id_overview);
$query = $this->db->get('overview_biostar')->rows();
return $query;
}
View:
<form method="post"action="<?php echo base_url(); ?>biostar/add_overview_product/<?php echo $type; ?>" >
<div class="box-body">
<?php foreach ($audio as $row){ ?>
<div class="checkbox">
<label>
<input type="checkbox" name="id_overview[]" value="<?php echo $row['title']; ?>"><?php echo $row['title']; ?>
</label>
</div>
<?php } ?>
</div>

$check_idoverview = $this->Biostar->check_idoverview($type,$id_overview);
$id_overview is an array. It should be a string.

Related

Dynamic checkbox and get the values from the checkbox checked

I am having difficulty creating dynamic checkboxes from db, and getting the values from the checkboxes when checked.
I have this Controller:
public function proporEvento(){
$natureza = $this->evento_model->naturezaEvento();
$apoio = $this->evento_model->apoioPertendido();
$espaco = $this->evento_model->espaco();
$material = $this->evento_model->material();
$suportgraf = $this->evento_model->suporteGrafico();
$audiovisual = $this->evento_model->audioVisual();
$data['title'] = 'Propor Evento';
$data['naturezaEvento'] = $natureza;
$data['apoioPertendido'] = $apoio;
$data['espaco'] = $espaco;
$data['material'] = $material;
$data['suporteGraf'] = $suportgraf;
$data['audioVisual'] = $audiovisual;
$this->load->view('cliente/clienteheaderdash_view', $data);
$this->load->view('cliente/clientemenu_view', $data);
$this->load->view('cliente/clienteproporevento_view', $data);
$this->load->view('cliente/clientefooterdash_view', $data);
}
Have this model:
public function naturezaEvento(){
$query = $this->db->get('tblnaturezaevento');
return $query->result();
}
public function apoioPertendido(){
$query = $this->db->get('tblapoio');
return $query->result();
}
public function espaco(){
$query = $this->db->get('tblespaco');
return $query->result();
}
public function material(){
$query = $this->db->get('tblmaterial');
return $query->result();
}
public function suporteGrafico(){
$query = $this->db->get('tblsuportegraf');
return $query->result();
}
public function audioVisual(){
$query = $this->db->get('tblaudiovisual');
return $query->result();
}
...and I have this view (one part for example):
<label>Apoio Pertendido</label>
<div class="form-group">
<?php foreach ($apoioPertendido as $row) { ?>
<label>
<input type="checkbox" class="flat-red" name="apoiopretendido[]" value="<?php echo $row->idApoio ?>" /> <?php echo $row->descricao; ?>
</label>
</br>
<?php } ?>
</div>
this code create the <input type="checkbox"...> correctly but how can I get the values from checked checkbox?
My form to go with this controller function:
public function etapa2(){
//$this->load->library('form_validation');
// $this->form_validation->set_rules('naturezaEvento', 'naturezaEvento', '|required|');
//$this->form_validation->set_rules('denominacao', 'denominacao', '|required|');
// $this->form_validation->set_rules('datainicio', 'datainicio', '|required|');
// $this->form_validation->set_rules('horainicio', 'horainicio', '|required|');
// $this->form_validation->set_rules('datafim', 'datafim', '|required|');
// $this->form_validation->set_rules('datainicio', 'datainicio', '|required|');
//if($this->form_validation->run() == FALSE){
//$this->index();
//}else{
$datageral['idcliente'] = $this->session->userdata('idcliente');
$datageral['idnatureza']=$this->input->post('naturezaEvento'); //insere o id do campo natureza da tabela tblnaturezaevento
$datageral['denominacaotitulo'] = $this->input->post('denominacao');
$datageral['datainicio']=$this->input->post('datainicio');
$datageral['horainicio']=$this->input->post('horainicio');
$datageral['datafim']=$this->input->post('datafim');
$datageral['horafim']=$this->input->post('horafim');
$datageral['planotrabalho']=$this->input->post('planotrabalho');
$datageral['raidertecnico']=$this->input->post('raidertecnico');
$datageral['programa']=$this->input->post('programa');
$datageral['mesa']=$this->input->post('mesa');
$datageral['notas']=$this->input->post('notas');
//'valorprovisorio' => $this->input->post('notas'), TODO fazer o valor provisório
//checkbox apoio
$apoiopertendido = $this->evento_model->apoioPertendido();
foreach ($apoiopertendido as $row) {
if ($this->input->post($row->checked, TRUE)===true){
$datageral[$row->tag] = $this->input->post($row->tag);
}
}
//checkbox espaços
$espacopertendido = $this->evento_model->espaco();
//$esp = array();
foreach ($espacopertendido as $row) {
if ($this->input->post($row->tag, TRUE)===true){
$datageral[$row->tag] = $this->input->post($row->tag);
}
}
//Material Necessário
$material = $this->evento_model->material();
//$materialnecessario = array();
foreach ($material as $row) {
$datageral[$row->tag] = $this->input->post($row->tag);
}
//checkbox suportes graficos
$suporteGrafico = $this->evento_model->suporteGrafico();
//$suporte = array();
foreach ($suporteGrafico as $row) {
if ($this->input->post($row->tag, TRUE)===true){
$datageral[$row->tag] = $this->input->post($row->tag);
}
}
//Registo Audio Visual
$audioVisual = $this->evento_model->audioVisual();
//$audiov = array();
foreach ($audioVisual as $row) {
if ($this->input->post($row->tag, TRUE)===true){
$datageral[$row->tag] = $this->input->post($row->tag);
}
}
$this->load->view('cliente/clienteheaderdash_view');
$this->load->view('cliente/clientemenu_view');
$this->load->view('cliente/clienteetapa2_view', $datageral);
$this->load->view('cliente/clientefooterdash_view');
// }
}

updating database on form submit codeigniter

I am having trouble updating my value in my database on form submit. I use codeigniter 2.20
I am getting a error Fatal error: Call to undefined method Model_setting::updateTheme() in E:\Xampp\htdocs\codeigniter-theme\admin\controllers\setting\setting.php on line 8
What I am trying to archive is on once have selected theme in form it will update the setting table value is where it gets posted to. It's not changing on form submit either.
I have autoloaded form_validation lib and form helper.
Model
<?php
class Model_setting extends CI_Model {
public function updateTheme() {
$this->db->select('*');
$this->db->where('group', 'config');
$this->db->where('key', 'config_template');
$this->db->where('value', $this->input->post('config_template')); // Need to update theme row
$query = $this->db->update('setting');
}
}
view
<form method="post" action="<?php echo $action;?>" role="form" class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label" for="input-template"><?php echo $entry_template; ?></label>
<div class="col-sm-10">
<select name="config_template" id="input-template" class="form-control">
<?php foreach ($templates as $template) { ?>
<?php if ($template == $config_template) { ?>
<option value="<?php echo $template; ?>" selected="selected"><?php echo $template; ?></option>
<?php } else { ?>
<option value="<?php echo $template; ?>"><?php echo $template; ?></option>
<?php } ?>
<?php } ?>
</select>
<br />
<img src="" alt="" id="template" class="img-thumbnail" />
</div>
</div>
<button type="submit" class="btn btn-md btn-primary">Save</button>
</form>
Controller
public function index() {
$this->load->model('setting/model_setting');
$this->model_setting->updateTheme();
if(null !==($this->input->post('config_template'))) {
$data['config_template'] = $this->input->post('config_template');
} else {
$data['config_template'] = $this->theme->get('value'); // Auto loaded Library Theme
}
$data['templates'] = array();
$directories = glob(DIR_CATALOG . 'views/theme/*', GLOB_ONLYDIR);
foreach ($directories as $directory) {
$data['templates'][] = basename($directory);
}
$this->form_validation->set_rules('config_template', '', 'callback_validate');
if($this->form_validation->run()) {
redirect('setting/store');
} else {
$this->lang->load('setting/setting', 'english');
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->lang->line('text_home'),
'href' => site_url('common/dashboard')
);
$data['breadcrumbs'][] = array(
'text' => $this->lang->line('heading_title'),
'href' => site_url('setting/setting')
);
$data['action'] = site_url('setting/setting');
$data['title'] = "Settings";
$data['entry_template'] = $this->lang->line('entry_template');
$data['header'] = $this->header($data);
$data['footer'] = $this->footer($data);
$this->load->view('setting/setting', $data);
}
}
You should read some basic CI first:
function index() {
$this->load->model('setting/model_setting'); //load model
if( $this->input->post(null) ){ //detect if form is submitted
if(null !==($this->input->post('config_template'))) {
$data['config_template'] = $this->input->post('config_template');
} else {
$data['config_template'] = $this->theme->get('value'); // Auto loaded Library Theme
}
if($this->form_validation->run()) {
$this->model_setting->updateTheme();
}
redirect('setting/store');
}else{ // load view only
$data['templates'] = array();
$directories = glob(DIR_CATALOG . 'views/theme/*', GLOB_ONLYDIR);
foreach ($directories as $directory) {
$data['templates'][] = basename($directory);
}
$this->form_validation->set_rules('config_template', '', 'callback_validate');
$this->lang->load('setting/setting', 'english');
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->lang->line('text_home'),
'href' => site_url('common/dashboard')
);
$data['breadcrumbs'][] = array(
'text' => $this->lang->line('heading_title'),
'href' => site_url('setting/setting')
);
$data['action'] = site_url('setting/setting');
$data['title'] = "Settings";
$data['entry_template'] = $this->lang->line('entry_template');
$data['header'] = $this->header($data);
$data['footer'] = $this->footer($data);
$this->load->view('setting/setting', $data);
}
}
You should first check if there is any post request, if there is update and redirect else show the form.
I have got it working.
Model
<?php
class Model_setting extends CI_Model {
public function update_theme() {
$this->db->where('key', 'config_template');
$this->db->set('value', $this->input->post('config_template'));
$this->db->update('setting');
}
}
controller
public function index() {
//$this->load->model('setting/model_setting');
$data['templates'] = array();
$directories = glob(DIR_CATALOG . 'views/theme/*', GLOB_ONLYDIR);
foreach ($directories as $directory) {
$data['templates'][] = basename($directory);
}
$this->form_validation->set_rules('config_template', '', 'callback_validate');
if($this->form_validation->run() == true) {
$this->load->model('setting/model_setting');
if($this->model_setting->update_theme()) {
$data['config_template'] = $this->input->post('config_template');
} else {
$data['config_template'] = $this->input->get('config_template');
}
redirect('setting/store');
} else {
$this->lang->load('setting/setting', 'english');
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->lang->line('text_home'),
'href' => site_url('common/dashboard')
);
$data['breadcrumbs'][] = array(
'text' => $this->lang->line('heading_title'),
'href' => site_url('setting/setting')
);
$data['action'] = site_url('setting/setting');
$data['title'] = "Settings";
$data['entry_template'] = $this->lang->line('entry_template');
$data['header'] = $this->header($data);
$data['footer'] = $this->footer($data);
$this->load->view('setting/setting', $data);
}
}

Update multiple checkbox in codeigniter

I'm new in codeigniter. I'm developing student Information project. There is one form with multiple check box that looks like this:
So first the inserted values are put inside the checkbox. The value is checked first but when I select another set of values, only the last value is updated.
I want to update multiple checkbox.
Thanks in advance.
MY Code
Controller:delete.php
<?php
class delete extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->helper('form');
$this->load->helper('html');
$this->load->model("delete_model");
$this->load->library("pagination");
//$this->load->library('table');
}
function GetAll()
{
$this->load->model('delete_model');
$data['query']=$this->delete_model->GetAll();
$this->load->view('studentview_view',$data);
}
//Get Record By Id
function getstudbyid($id)
{
$this->load->model("delete_model");
$data['student']=$this->delete_model->getstuddetailsbyid($id);
//echo $this->db->last_query();
$this->load->view("displayview",$data);
}
//pagination
function test($start_from = 1)
{
$this->load->model('delete_model');
$this->load->library('pagination');
// $data['query']=$this->delete_model->GetAll();
$data = array();
$per_page = 3;
$this->load->model('delete_model');
$total = $this->delete_model->record_count();
$start = $per_page * ($start_from-1);
$data['student'] = $this->delete_model->get($per_page, $start);
$config['base_url'] = base_url() . "index.php/delete/test";
$config['total_rows'] = $total;
$config['per_page'] = $per_page;
$config['uri_segment'] = 2;
$config['num_links'] = 2;
$config['use_page_numbers'] = TRUE;
//$config['overwrite'] = TRUE;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
foreach($data['student'] as $key=>$value){
//echo $key;
foreach($value as $k=>$v)
{
if ( $k == 'id') {
anchor('delete/del'.$v,'delete');
anchor('delete/input/'.$v,'Edit');
}
}}
// $data['table'] = $this->table->generate();
$this->load->view('studentlist' ,$data);
}
//Delete Record
function del($id){
$this->load->helper('html');
$this->load->model('delete_model');
if((int)$id > 0){
$this->delete_model->delete($id);
}
$data = $this->delete_model->delete();
$data['student'] = $this->delete_model->delete();
redirect($_SERVER['HTTP_REFERER']);
//$this->load->view('studentlist',$data);
}
//Update Record
function input($id=0)
{
$this->load->model('delete_model');
if($this->input->post('btnupdate'))
{
if($this->input->post('id'))
{
$this->delete_model->entry_update();
echo $this->db->last_query();
}
else
{
$this->student_model->student();
}
}
$data = $this->delete_model->student_data();
if((int)$id > 0)
{
$query = $this->delete_model->getstuddetailsbyid($id);
print_r($query);
//echo $this->db->last_query();
// $data['fid']['value'] = $query['id'];
// $data['up_std_name']['value'] =$query['std_name'];
// $data['up_std_address']['value']=$query['std_address'];
// $data['stud_class']['value']=$query['std_class'];
// $data['up_std_language']['value']=$query['std_language'];
$data['fid'] = $query['id'];
$data['up_std_name']=$query['std_name'];
$data['up_std_address']=$query['std_address'];
$data['stud_class']=$query['std_class'];
$data['up_std_language']=$query['std_language'];
$data['up_std_gender'] =$query['std_gender'];
echo "--------";
//print_r($data);
echo "----bhumika----";
//print_r($query['std_languag']);
print_r($data['up_std_language']);
echo "---a---";
echo "<br/>";
echo "<br/>";
// if($query['std_gender']=='F')
// {
// $data['up_std_gender']['checked'] = TRUE;
// }
// else
// {
// $data['up_std_gender']['checked'] = FALSE;
// }
// $data['up_std_birthdate']['value']=$query['std_birthdate'];
// $data['up_std_photo']['value']=$query['std_photo'];
// $data['up_std_ilanguage']['value']=$query['std_int_language'];
// print_r($data['up_std_ilanguage']['value']);
$data['up_std_birthdate']=$query['std_birthdate'];
$data['up_std_photo']=$query['std_photo'];
$data['up_std_ilanguage']=$query['std_int_language'];
// print_r($data['up_std_ilanguage']);
}
$this->load->view('finalview',$data);
}
}
?>
Model:delete_model.php
<?php
class delete_model extends CI_Model{
function stud_delete_model()
{
parent::CI_Model();
}
//View Record
public function GetAll()
{
$this->load->database();
$query=$this->db->get('student');
return $query->result();
}
//paging
public function record_count() {
$this->load->database();
$this->db->count_all("student");
// echo $this->db->last_query();
return $this->db->count_all("student");
}
function get($limit,$start_from)
{
$this->load->database();
$sql = "SELECT * FROM student LIMIT $start_from, $limit";
$query = $this->db->query($sql);
// echo $this->db->last_query();
return $query->result_array();
}
//view Record by id
public function getstuddetailsbyid($id)
{
$this->load->database();
$query=$this->db->get_where('student',array('id'=>$id));
//$this->db->last_query();
return $query->row_array();
}
//Delete Record
function delete($id)
{
$this->load->database();
$this->db->where('id',$id);
$this->db->delete('student');
}
//Update Record
function entry_update()
{
$this->load->database();
$date=$this->input->post('datepicker');
$data=array(
'std_name'=>$this->input->post('std_name1'),
'std_address'=>$this->input->post('std_address1'),
'std_class'=>$this->input->post('std_class'),
'std_language'=>$this->input->post('std_language1'),
'std_gender'=>$this->input->post('std_gender1'),
'std_birthdate'=>date('Y-m-d', strtotime(str_replace('-', '/', $date))),
'std_photo'=>$this->input->post('userfile'),
'std_int_language'=>$this->input->post('std_ilanguage1')
);
//$t=$this->input->post('std_language1');
// echo "***";
// echo $t;
//print_r($t);
// if(isset($this->input->post['std_language1']))
// {
// $q=implode(',',$this->input->post['std_language1'] );
// echo "(((((";
// print_r($q);
//$data['q']=$q;
//print_r($data);
// }
// else
// {
// $q='';
// }
// echo $q;
print_r($data);
$this->db->where('id',$this->input->post('id'));
$this->db->update('student',$data);
}
function student_data()
{
//Label of form
// $data=array();
//$data['fid'] =array();
//$data['stud_class'] = '';
//$data['up_std_name'] = array();
//$data['up_std_address']=array();
$data['fid'] ='';
$data['up_std_name'] = '';
$data['up_std_address']='';
$data['stud_class'] = '';
$data['up_std_language']='';
$data['up_std_gender']='';
$data['up_std_birthdate']='';
$data['up_std_photo']='';
//echo "ddddddd";
// print_r($data['up_std_address']);
//$data['std_name1']="Name";
//$data['std_address1']="Address";
//$data['std_class']="Class";
// $data['up_std_class_list']=array(
// 'select' => 'Select',
// '10th' => '10th',
// '12th' => '12th',
// 'Graduate' => 'Graduate'
// );
//$data['std_language1']="Language";
//$data['std_gender1']="Gender";
//$data['std_birthdate']="Birthdate";
//$data['std_photo']="Photo";
//$dat['std_int_language']="Interested Language";
//values get from the database
//$data['fid']['value'] = 0;
//print_r($data['fid']['value']);
// $data['up_std_name'] = array(
// 'name' => 'std_name',
// 'id' => 'std_name',
// 'maxlength' => '50',
// 'size' => '30',
// 'style' => 'width:30%'
// );
// $data['up_std_address']=array(
// 'name'=>'std_address',
// 'id'=>'std_address',
// 'rows'=>'2',
// 'columns'=>'5',
// 'width'=>'20',
// 'size'=>'50',
// 'maxlength' => '100',
// 'style'=>'width:30%'
// );
// $data['up_std_language']=
// array('name'=>'std_language',
// 'value'=>'.Net',
// 'checked'=>True
// );
// (array('name'=>'std_language',
// 'value'=>'PHP',
// 'checked'=>false
// )
// );
// (array('name'=>'std_language',
// 'value'=>'JAVA',
// 'checked'=>false
// )
// );
// (array('name'=>'std_language',
// 'value'=>'Android',
// 'checked'=>false
// )
// );
// (array('name'=>'std_language',
// 'value'=>'Iphone',
// 'checked'=>false
// )
// );
//print_r($data['up_std_language']);
// $data['up_std_gender']=(array
// (
// "name"=>"std_gender",
// "id"=>"std_gender",
// "value"=>"M",
// 'checked'=>set_radio('std_gender', 'M', True)
// )
// );
// ?>
<?php
// (array
// (
// "name"=>"std_gender",
// "id"=>"std_gender",
// "value"=>"F",
// 'checked'=>set_radio('std_gender', 'F', True)
// )
// );
?>
<?php // $data['up_std_birthdate']=''; ?>
<td>
</td>
<?php
//$data['up_std_photo']='';
// $data['up_std_ilanguage']=array(
// 'select' => 'Select',
// '.Net' => '.Net',
// 'PHP' => 'PHP',
// 'JAVA' => 'JAVA',
// 'Android'=> 'Android',
// 'IPhone' => 'IPhone'
// );
?>
<?Php return $data;
}
}
?>
View:finalview.php
<?php
//echo validation_errors();
?>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
$( "#datepicker" ).datepicker();
dateFormat: 'yyyy-mm-dd'
onclick="javascript: ('datepicker','yyyyMMdd','arrow',true,'12',true)"
});
</script>
</head>
<body>
<? echo form_open('delete/input');
//print_r($fid); ?>
<? echo form_hidden('id',$fid); ?>
<table>
<tr>
<td>
<label for='std_name'>Student Name</label>
</td>
<td>
<?php
$data = array(
'name' => 'std_name1',
'id' => 'std_name1',
'maxlength' => '100',
'size' => '50',
//'value' => set_value('std_name1'),
'style' => 'width:50%'
);
//echo form_input('std_name1',set_value('std_name1'));
echo form_input('std_name1',$up_std_name);
//print_r($up_std_name);
//echo $std_name1;
//print_r($std_name1);
?></td>
</tr>
<tr>
<td>
<label for='std_address'>Address</label>
</td>
<td>
<?php
$data=array(
'name'=>'std_address1',
'id'=>'std_address1',
'rows'=>'3',
'columns'=>'3',
'size'=>'50',
'maxlength' => '100',
'style'=>'width:50%'
);
echo form_textarea('std_address1',$up_std_address);
print_r($up_std_address);
?>
</td>
</tr>
<tr>
<td>
<label for='std_class'>Class</label>
</td>
<td>
<?php
$options = array(
'select' => 'Select',
'10th' => '10th',
'12th' => '12th',
'Graduate' => 'Graduate'
);
echo form_dropdown('std_class',$options,$stud_class);
print_r($stud_class);
?></td>
<tr>
<td>
<label for='std_language'>Language</label>
</td>
<td>
<?php
// $query['']=array('.Net'=>'.Net','PHP'=>'PHP');
// print_r($query);
//echo "----charmi---";
// print_r($up_std_language);
// print_r($data['up_std_language']['value']);
// print_r($language);
//echo "bbb";
//echo "<br/>";
//echo set_checkbox(in_array('std_language', $language) // TRUE checks the box, FALSE does no
// );
$language = explode(',',$up_std_language);
$a='';
$b='';
$c='';
$d='';
$e='';
//print_r($t);
// if(isset ($this->input->post['std_language1'])) {
// $role = implode(',', $this->input->post('std_language1'));
// print_r($role);
// } else {
// $role = '';
// }
if(in_array('.Net',$language))
{
$a='checked="checked"';
//echo $a;
}
if(in_array('PHP',$language))
{
$b='checked="checked"';
//echo $b;
}
if(in_array('JAVA',$language))
{
$c='checked="checked"';
}
if(in_array('Android',$language))
{
$d='checked="checked"';
}
if(in_array('IPhone',$language))
{
$e='checked="checked"';
}
// $skill = implode(',', $this->input->post('skill'));
//$data['skill'] = $skill;
echo form_checkbox('std_language1','.Net',$a). ".Net";
echo form_checkbox('std_language1','PHP',$b)."PHP";
echo form_checkbox('std_language1','JAVA',$c)."JAVA";
echo form_checkbox('std_language1','Android',$d)."Android";
echo form_checkbox('std_language1','IPhone',$e)."IPhone";
$t=$this->input->post('std_language1';
echo "***";
echo $t;
//print_r($t);
//print_r($language);
$v=$language;
print_r ($v);
if(isset($t))
{
$q=implode(',',$this->input->post['std_language1'] );
echo "(((((";
print_r($q);
//$data['q']=$q;
//print_r($data);
}
// else
// {
// $q='';
// }
// echo $q;
?>
</td>
</tr>
<tr>
<td>
<label for='std_gender'>Gender</label>
</td>
<td>
<?php
//echo $gender=$this->input->post('std_gender1');
// if($gender=='male' || empty($gender)) $mchecked=true;
// else if($gender=='female') $fchecked=true;
// if($gender=="male")
// {
// echo "checked";
// }
// echo form_radio('std_gender1', 'male', #$mchecked, 'id=male').form_label('Male', 'male');
// echo form_radio('std_gender1', 'female', #$fchecked, 'id=female').form_label('Female','female');
//print_r($up_std_gender);
// $checked = '';
// if($checked)
// {
// $checked='F';
//echo $checked;
//$false='M';
// }
// else
// {
// $checked='M';
//$false='F';
// }
// echo form_radio('std_gender1', 'M', $checked)."Male";
// echo form_radio('std_gender1', 'F', $checked)."Female";
$gender=array(
'name'=>'std_gender1',
'id'=>'std_gender1'
//'checked'=>set_value('std_gender1', 'F', FALSE)
);
echo "=======";
print_r($up_std_gender);
// $checked = '';
$w='M';
$m='F';
if($up_std_gender)
{
$w='checked="checked"';
}
else
if($up_std_gender)
{
$m='checked="checked"';
}
//echo $checked;
// $false='M';
// }
// else
// {
// $checked='M';
// $false='F';
// }
echo form_radio('std_gender1', 'M',$w)."Male";
echo form_radio('std_gender1', 'F',$m)."Female";
// echo form_radio($gender,$up_std_gender,set_value('std_gender1', 'F', TRUE))."Male";
// echo form_radio($gender,'F',set_value('std_gender1', 'M', TRUE))."Female";
// echo form_radio(array
// (
// "name"=>"std_gender1",
// "id"=>"std_gender1",
// "value"=>"F",
// 'checked'=>set_value('std_gender1', 'F', FALSE)
// )
// );
// ?>
<?php
// echo form_radio(array
// (
// "name"=>"std_gender1",
// "id"=>"std_gender1",
// "value"=>"M",
// 'checked'=>set_value('std_gender1', 'M', FALSE)
// )
// );
?>
</td>
</tr>
<tr>
<td valign="top">
<label for='std_birthdate'>Birthdate</label>
</td>
<?php
$date=array(
'name'=>'datepicker',
'id'=>'datepicker'
);
?>
<td><?php echo form_input($date,$up_std_birthdate); ?><!--<input type="text" id="datepicker" name="datepicker" />--></td>
</tr>
<tr>
<td>
<label for='std_photo'>Photo</label>
</td>
<td>
<?php //echo $error;?>
<?php echo form_open_multipart('student/do_upload');
echo form_upload('userfile',$up_std_photo);
echo form_label($up_std_photo);
?>
<!--<input type="file" name="userfile" size="20" />-->
<?php echo form_close();?>
</td>
</tr>
<tr>
<td>
<label for='std_ilanguage[]'>Interested Language</label>
</td>
<td>
<!--<select size="" name="ilanguage[]" multiple="multiple">
<option>.Net</option>
<option>PHP</option>
<option>JAVA</option>
<option>Android</option>
<option>IPhone</option>
</select>-->
<?php
$options = array(
'select' => 'Select',
'.Net' => '.Net',
'PHP' => 'PHP',
'JAVA' => 'JAVA',
'Android'=> 'Android',
'IPhone' => 'IPhone'
);
//$select=array('.Net','PHP','JAVA','Android','IPhone');
echo form_multiselect('std_ilanguage',$options);
?></td>
</tr>
<tr>
<td>
<? echo form_submit('btnupdate','Update!'); ?>
</td>
</tr>
</table>
<p><?php echo anchor('delete/test','Go To View!'); ?></p>
</form>
</html>
<? echo form_close(); ?>
I'm using implode() function but it doesn't get the updated vales so give me solution
Here, all the records of default value is shown into controls but when I checked more than one, it will update only single a checkbox.
Thanks again.

Undefined Variable taskid in view

i am working on view and i want to print task id from database in my view
following is my Controller function
Controller :-
function editMilestone($editid){
//, $taskid) {
if ($this->session->userdata('logged_in')) {
$session_data = $this->session->userdata('logged_in');
$id = $session_data['id'];
$username = $session_data['username'];
$is_master_admin = $session_data['master'];
$imagethumb = $session_data['imagethumb'];
$status_result = $this->getstatus->getEnumValues(MILESTONE, 'status');
$result = $this->milestonemodel->getEditMilestone($editid , $taskid);
$pendingbug = $this->bugmodel->getBug($id, $is_master_admin);
$pendingtask = $this->taskmodel->getTask($id, $is_master_admin);
if ($result == true) {
$session_msg_data = $this->session->userdata('msg');
if (isset($session_msg_data) && !empty($session_msg_data)) {
$milestonemsg = isset($session_msg_data['milestonemsg']) ? $session_msg_data['milestonemsg'] : '';
$milestoneopt = isset($session_msg_data['milestoneopt']) ? $session_msg_data['milestoneopt'] : '';
$this->session->unset_userdata('msg');
} else {
$milestonemsg = '';
$milestoneopt = '';
}
$data = '';
$data = array('username' => $username,
'is_master_admin' => $is_master_admin,
'imagethumb' => $imagethumb,
'result' => $result,
'taskid' => $taskid,
//'editid'=>$editid,
'status_result' => $status_result,
'profileopt' => $milestoneopt,
'profilemsg' => $milestonemsg,
'pendingtask' => $pendingtask,
'pendingbug' => $pendingbug
);
$this->load->view('milestone/edit_milestone', $data);
} else {
redirect('task', 'refresh');
}
} else {
//If no session, redirect to login page
redirect('home/logout', 'refresh');
}
}
Model :-
function getEditMilestone($id){
//, $taskid) {
$status = array(PUBLISH, UNPUBLISH, BLOCK);
$this->db->select('*');
$this->db->from(MILESTONE);
$this->db->where('id', $id);
//$this->db->where('taskid', $taskid);
$this->db->where_in('status', $status);
$this->db->limit(1);
//echo $this->db-last_query();
$query = $this->db->get();
if ($query->num_rows() == 1) {
return $query->result();
} else {
return false;
}
}
VIEW :- Milestone View
<div class="message">
<span class="arrow"></span>
<span class="body">
<?php
echo '<b> <U> Task Title </U>:- </b> &nbsp';
echo $milestone_row->tasktitle;
echo '<br/>';
echo '<b> <U> Workspace Title </U>:- </b> &nbsp';
echo $milestone_row->workspacetitle;
echo '<br/>';
echo '<b> <U> Description </U>:- </b> &nbsp';
echo $milestone_row->description;
echo '<br/>';
echo '<b> <U> Hours </U>:- </b> &nbsp';
echo $milestone_row->esthours;
echo 'hrs';
echo '<br/>';
echo '<b> <U> Minutes </U>:- </b> &nbsp';
echo $milestone_row->estmin;
echo'mins';
echo '<br/>';
?>
Edit
</div>
When i click on edit link from above view it will transfer to editMilestone from controller and it wil transfer to to another view that is edit_milestone
View :- edit_milestone
<?php
$attributes = array('class' => 'form-horizontal', 'id' => 'form_add_milestone');
echo form_open('milestone/validateEditMilestone/'.$result[0]->id.'/'.$taskid, $attributes);
?>
<input type="text" readonly="readonly" value="<?php echo $taskid; ?>" name="taskid" />
I would like to print my taskid here from database
The problem is with the code. you are using $taskid when its not initialized in following line,
$result = $this->milestonemodel->getEditMilestone($editid , $taskid);
and when you put that value in $data it does not work because there is no value in $taskid
you should pass $taskid as parameter in Milestone View or create another query to fetch it from db.

PHP Todo CheckList Checked Feature

I need help with a PHP ToDo List. I have most of it working except for the check box to move it from a completed list to a still need to do list. here is the code I have so far:
For the edit screen:
%% views/header.html %%
<h1>{{$title}}</h1>
<div class='inputs'>
<form action="##todo/update##" method="post">
<input type="hidden" id="id" name="id" value="{{$todo['id']}}" />
<label for="description">Description:</label>
<input type="text" id="description" name="description" value="{{$todo ['description']}}" />
<label for="done">Done?:</label>
<input type="checkbox" id="done" name="done" value="1" />
<input type="submit" value="Update" />
<form>
</div>
<p><< Back</p>
%% views/footer.html %%
For the todo.inc file:
<?php
include_once "include/util.inc";
include_once "models/todo.inc";
function safeParam($arr, $index, $default) {
if ($arr && isset($arr[$index])) {
return $arr[$index];
}
return $default;
}
function get_view($params) {
$id = safeParam($params, 0, false);
if ($id === false) {
die("No todo id specified");
}
$todo = findToDoById($id);
if (!$todo) {
die("No todo with id $id found.");
}
// #formatter:off
renderTemplate(
"views/todo_view.inc",
array(
'title' => 'Viewing To Do',
'todo' => $todo
)
);
// #formatter:on
}
function get_list($params) {
$todos = findAllCurrentToDos();
$dones = findAllDoneToDos();
// #formatter:off
renderTemplate(
"views/index.inc",
array(
'title' => 'To Do List',
'todos' => $todos,
'dones' => $dones
)
);
// #formatter:on
}
function get_edit($params) {
$id = safeParam($params, 0, false);
if (!$id) {
die("No todo specified");
}
$todo = findToDoById($id);
if (!$todo) {
die("No todo found.");
}
// #formatter:off
renderTemplate(
"views/todo_edit.inc",
array(
'title' => 'Editing To Do',
'todo' => $todo
)
);
// #formatter:on
}
function post_add($params) {
if (!isset($_POST['description'])) {
die("no description given");
}
$description = htmlentities($_POST['description']);
addToDo($description);
redirectRelative("index");
}
function validate_present($elements) {
$errors = '';
foreach ($elements as $element) {
if (!isset($_POST[$element])) {
$errors .= "Missing $element\n";
}
}
return $errors;
}
function post_update($params) {
$errors = validate_present(array('id', 'description', 'done'));
if ($errors) {
die($errors);
}
$id = $_POST['id'];
$description = $_POST['description'];
$done = $_POST['done'];
updateToDo($id, $description, $done);
redirectRelative("todo/view/$id");
}
function get_delete($params) {
$id = safeParam($params, 0, false);
if (!$id) {
die("No todo specified");
}
$todo = findToDoById($id);
if (!$todo) {
die("No todo found.");
}
deleteToDo($id);
redirectRelative("index");
}
?>
Your error is in these two functions.
function validate_present($elements) {
$errors = '';
foreach ($elements as $element) {
if (!isset($_POST[$element])) {
$errors .= "Missing $element\n";
}
}
return $errors;
}
function post_update($params) {
$errors = validate_present(array('id', 'description', 'done'));
if ($errors) {
die($errors);
}
$id = $_POST['id'];
$description = $_POST['description'];
$done = $_POST['done'];
updateToDo($id, $description, $done);
redirectRelative("todo/view/$id");
}
You are attempting to validate that done exists in validate_present when called by post_update. done obviously cannot exists since it is not sent to the server when the checkbox is not checked. The $_POST does not even contain that variable, so it returns that element is missing (since it technically is). I would leave validate_present alone and change post_update as follows:
function post_update($params) {
$errors = validate_present(array('id', 'description'));
if ($errors) {
die($errors);
}
$id = $_POST['id'];
$description = $_POST['description'];
$done = (isset($_POST['done'])? 1 : 0);
updateToDo($id, $description, $done);
redirectRelative("todo/view/$id");
}

Categories