article post not updating in codeigniter blog - php

I am new in codeigniter. I build a cms with codeigniter for blog. But when i want edit a article post and want to save it, it create new one post not update old post which i edited.
Please help me.
My Article Edit crontroller:
public function edit ($id = NULL)
{
// Fetch a article or set a new one
if ($id) {
$this->data['article'] = $this->article_m->get($id);
count($this->data['article']) || $this->data['errors'][] = 'article could not be found';
}
else {
$this->data['article'] = $this->article_m->get_new();
}
// categories for dropdown
$this->data['all_categories'] = $this->article_m->join();
// Set up the form
$rules = $this->article_m->rules;
$this->form_validation->set_rules($rules);
// Process the form
if ($this->form_validation->run() == TRUE) {
$data = $this->article_m->array_from_post(array(
'title',
'extra_title',
'slug',
'image',
'category_id',
'body',
'pubdate'
));
$this->article_m->save($data, $id);
redirect('admin/article');
}
// Load the view
$this->data['subview'] = 'admin/article/edit';
$this->load->view('admin/_layout_main', $this->data);
}
My Models:
public function array_from_post($fields){
$data = array();
foreach ($fields as $field) {
$data[$field] = $this->input->post($field);
}
return $data;
}
public function get($id = NULL, $single = FALSE){
if ($id != NULL) {
$filter = $this->_primary_filter;
$id = $filter($id);
$this->db->where($this->_primary_key, $id);
$method = 'row';
}
elseif($single == TRUE) {
$method = 'row';
}
else {
$method = 'result';
}
if (!count($this->db->ar_orderby)) {
$this->db->order_by($this->_order_by);
}
return $this->db->get($this->_table_name)->$method();
}
public function get_by($where, $single = FALSE){
$this->db->where($where);
return $this->get(NULL, $single);
}
public function save($data, $id = NULL){
// Set timestamps
if ($this->_timestamps == TRUE) {
$now = date('Y-m-d H:i:s');
$id || $data['created'] = $now;
$data['modified'] = $now;
}
// Insert
if ($id === NULL) {
!isset($data[$this->_primary_key]) || $data[$this->_primary_key] = NULL;
$this->db->set($data);
$this->db->insert($this->_table_name);
$id = $this->db->insert_id();
}
// Update
else {
$filter = $this->_primary_filter;
$id = $filter($id);
$this->db->set($data);
$this->db->where($this->_primary_key, $id);
$this->db->update($this->_table_name);
}
return $id;
}
public function get_new ()
{
$article = new stdClass();
$article->title = '';
$article->extra_title = '';
$article->slug = '';
$article->image = '';
$article->category_id = '';
$article->body = '';
$article->pubdate = date('Y-m-d');
return $article;
}
public function join()
{
$this->db->select('name,categories.id as category_id');
$this->db->from($this->_table_name);
$this->db->join('categories', 'categories.id = category_id','right');
$Q = $this->db->get();
if ($Q->num_rows() > 0){
foreach ($Q->result_array() as $row){
$data[$row['category_id']] = $row['name'];
}
}
$Q->free_result();
return $data;
}
My View:
<?php echo validation_errors(); ?>
<?php echo form_open_multipart('admin/article/edit'); ?>
<table class="table">
<tr>
<td>Publication date</td>
<td><?php echo form_input('pubdate', set_value('pubdate', $article->pubdate), 'class="datepicker"'); ?></td>
</tr>
<tr>
<td>Category</td>
<td><?php
$js = 'id="category_id" onChange="some function();"';
echo form_dropdown('category_id', $all_categories, set_value('category_id', $article->category_id), $js); ?></td>
</tr>
<tr>
<td>Title</td>
<td><?php echo form_input('title', set_value('title', $article->title)); ?></td>
</tr>
<tr>
<td>Extra Title (Optional)</td>
<td><?php echo form_input('extra_title', set_value('extra_title', $article->extra_title)); ?></td>
</tr>
<tr>
<td>Slug</td>
<td><?php echo form_input('slug', set_value('slug', $article->slug)); ?></td>
</tr>
<tr>
<td>Upload Image</td>
<td>
<div class="input-append">
<?php echo form_input('image', set_value('image', $article->image),'id="fieldID"'); ?>
Select
</div>
</td>
</tr>
<tr>
<td>Body</td>
<td><?php echo form_textarea('body', set_value('body', $article->body), 'class="tinymce"'); ?></td>
</tr>
<tr>
<td></td>
<td><?php echo form_submit('submit', 'Save', 'class="btn btn-primary"'); ?></td>
</tr>
</table>
<?php echo form_close();?>
Please Help Me.

You have to pass the id to the controller. In your view you are telling the form to submit to
article/edit but not the id.
<?php echo validation_errors(); ?>
<?php echo form_open_multipart('admin/article/edit/'.$article->id); ?>
...
You'll probably get some warnings if $article is not set, so you may want to put in some checks for when you're adding a new item.

Related

Update field using foreach loop in codeigniter not working

I have an issue I´m trying to update a field from a column using codeigniter , I display results from database using a foreach loop then I want to add a button called "reactivate" to change the status of that column, the PROBLEM is that it updates all the fields I just want to update the row I´m clicking in but it changes the 'Status' of all the other accounts, I don´t know how to solve this issue. Thanks in advance.
This is my view:
div class='container'>
<h5>Histórico</h5>
<table id='table' class='table'>
<thead>
<tr>
<th>INTERNO</th>
<th>CLABE</th>
<th>FECHA_ALTA</th>
<th>FECHA_BAJA</th>
<th>STATUS</th>
<th>ACCIÓN</th>
</thead>
<tbody>
<?php
foreach ($mos-> result() as $row) {
echo "<tr>";
echo "<td>".$row->Interno;"</td>";
echo "<td>".$row->Clabe;"</td>";
echo "<td>".$row->Fecha_alta;"</td>";
echo "<td>".$row->Fecha_baja;"</td>";
echo "<td>".$row->Status;"</td>";
echo "<td><input type='submit' id='ReActivar' name='ReActivar' class='btn btn-success' value='ReActivar' onclick='return validacion();' disabled><span id='msg'></span></td>";
"</tr>";
}
?>
</tbody>
</table>
</div>
This is my controller:
function decision(){
if (!empty($_POST['actualizar'])) {
$this->validaclabe();
}
if (!empty($_POST['Desactivar'])) {
$this->update_Status();
}
if (!empty($_POST['ReActivar'])) {
$this->update_Status_again();
}
}
function update_Status_again()
{
$this->load->helper('date');
date_default_timezone_set('America/Mexico_City');
$now = date('Y-m-d H:i:s');
$Interno = $this->input->post('Interno');
$Status = $this->input->post('activo');
$data = array(
'Status' => ! empty($Status) ? $Status : 'A',
'Fecha_alta' => $now,
);
//$data['status'] = ! empty($Status) ? $Status : 'I';
if ( ! empty($Interno))
{
$updated = $this->consultas_M->update_Status($Interno, $data);
if($updated)
{
//echo " update successful...";
$this->logueado();
//redirect('index.php/Datos/search2');
}
else
{ echo "update not successful...";}
} else
{ echo "Interno not found ..."; }
}
This is the model:
function muestra_inactivos($Interno)
{ $Status = 'A';
//$Interno = $this->input->get('Interno');
$this->db->select('Interno, Clabe, Fecha_alta, Fecha_baja, Status');
$this->db->where('Status !=', $Status);
$this->db->where('Interno =', $Interno);
$q= $this->db ->get('cuentas');
if($q -> num_rows() >= 0){
return $q;
}else{
return false;
}
}
function update_Status_again($Interno,$data)
{
$this->db->where('Interno', $Interno);
return $this->db->update('cuentas', $data);
if ( $this->db->affected_rows() > 0 )
{
return TRUE;
}
else
{
return FALSE;
}
}
This is also a picture I also don´t know why one button is disabled and the other is not.

Array to string conversion on CodeIgniter

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.

Call to a member function result() on a non-object

There is an error message when my view is being loaded. "Call to a member function result() on a non-object"
How do I fix this?
This is the loop in my View: discussion/view.php
<?php foreach ($query->result() as $result) : ?>
<tr>
<td>
<?php echo anchor('comments/index/'.$result->ds_id,$result->ds_title) . ' '
. $this->lang->line('comments_created_by') . $result->usr_name; ?>
<?php echo anchor('discussions/flag/'.$result->ds_id,
$this->lang->line('discussion_flag')) ; ?>
<br />
<?php echo $result->ds_body ; ?>
</td>
</tr>
<?php endforeach ; ?>
and this is the function index in my Comments Controller:
public function index() {
if ($this->input->post()) {
$ds_id = $this->input->post('ds_id');
} else {
$ds_id = $this->uri->segment(3);
}
$page_data['discussion_query'] = $this->Discussions_model->fetch_discussion($ds_id);
$page_data['comment_query'] = $this->Comments_model->fetch_comments($ds_id);
$page_data['ds_id'] = $ds_id;
$this->form_validation->set_rules('ds_id', $this->lang->line('comments_comment_hidden_id'), 'required|min_length[1]|max_length[11]');
$this->form_validation->set_rules('comment_name', $this->lang->line('comments_comment_name'), 'required|min_length[1]|max_length[25]');
$this->form_validation->set_rules('comment_email', $this->lang->line('comments_comment_email'), 'required|min_length[1]|max_length[255]');
$this->form_validation->set_rules('comment_body', $this->lang->line('comments_comment_body'), 'required|min_length[1]|max_length[5000]');
if ($this->form_validation->run() == FALSE) {
$this->load->view('common/header');
$this->load->view('nav/top_nav');
$this->load->view('comments/view', $page_data);
$this->load->view('common/footer');
} else {
$data = array('cm_body' => $this->input->post('comment_body'),
'usr_email' => $this->input->post('comment_email'),
'usr_name' => $this->input->post('comment_name'),
'ds_id' => $this->input->post('ds_id')
);
if ($this->Comments_model->new_comment($data)) {
redirect('comments/index/'.$ds_id);
} else {
// error
$this->data['message'] = 'Error!';
}
}
}

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.

Codeigniter view shows 0 record

i've insert 5 rows into ms_kategori_material table, and made some model here
function read()
{
$query = $this->db->get('ms_kategori_material');
if($query->num_rows()>0)
{
foreach ($query->result_array() as $value) {
echo $value['Kode_Kategori_Material_Jasa'];
echo $value['Nama_Material_Jasa'];
}
return $value;
}
else
{
return null;
}
}
and controllers
function index()
{
$data['kirim'] = $this->m_kategorimaterial->read();
echo $data; //returns KKMJ001batuKKMJ002batuKKMJ003batuKKMJ004batuKKMJ005batuArray
$this->load->view('v/vkategorimaterial',$data);
}
and the views
<?php
if ( !empty($kirim) ) {
$no = 1;
foreach ($kirim as $row) { ?>
<tr id="row">
<td id="no"><?php echo $no;?></td>
<td id="judul"><?php echo $row->Kode_Kategori_Material_Jasa;?></td>
<td id="kategori"><?php echo $row->Nama_Material_Jasa;?></td>
</tr> ?>
<?php
$no++;
}
} else { ?>
<tr id="row">
<td colspan="6" align="center">Data tidak ditemukan</td>
//the screen shows 'data tidak ditemukan' </tr>
<?php
}
?>
this is so confusing, since i can see the data in the controller, then pass them into the views, views said no data received
In your model
if($query->num_rows()>0)
{
foreach ($query->result_array() as $value) {
echo $value['Kode_Kategori_Material_Jasa'];
echo $value['Nama_Material_Jasa'];
}
return $value;
}
it's wrong, it should be
if($query->num_rows()>0)
{
return $query->result();
}
and in your controller you should have
function index()
{
$this->load->model('m_kategorimaterial'); // load it if it's not autoloaded
$data['kirim'] = $this->m_kategorimaterial->read();
$this->load->view('v/vkategorimaterial',$data);
}
Just reread your code. You're returning $value but never populating it. See below.
{
$query = $this->db->get('ms_kategori_material');
if($query->num_rows()>0)
{
$value = $query->result(); // or result_array() but you're using it as an object in the view not an array.
return $value;
}
else
{
return null;
}
}
You are actually not returning the results in your model,
replace
foreach ($query->result_array() as $value)
{
echo $value['Kode_Kategori_Material_Jasa'];
echo $value['Nama_Material_Jasa'];
}
with
if($query->num_rows()>0)
{
return $query->result();
}

Categories