I believe in order to help you, we need to see the whole of your controller and models.
Copying and pasting here parts of it doesn't really helps a lot to be honest.
⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠
Posted 07 February 2013 - 21:44 PM
I believe in order to help you, we need to see the whole of your controller and models.
Copying and pasting here parts of it doesn't really helps a lot to be honest.
Posted 07 February 2013 - 21:49 PM
look at this:
$crud->add_action('Send', '', 'standby/standby_v/copyrows','ui-icon-plus');
echo $this->copyrows();
the copyrows need a argument:
echo $this->copyrows($id);
share your project and I test it on my server.
Posted 07 February 2013 - 21:52 PM
thanks David for your interest!
my controller standby.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Standby extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->database();
$this->load->library('grocery_crud');
$this->load->helper('url');
}
function index()
{
}
function standby_v()
{
try{
$crud = new grocery_CRUD();
$crud->set_theme('datatables');
$crud->set_table('standby');
$crud->set_subject('Standby');
$crud->set_language('spanish');
$crud->required_fields(
'id_standby',
'name',
'email'
);
$crud->columns(
'id_standby',
'name',
'email',
'address',
'phone',
'password'
);
$crud->add_action('Send', '', 'copyrows','ui-icon-plus');
$output = $crud->render();
$this->load->view('standby/standby_v', $output);
}catch(Exception $e){
show_error($e->getMessage().' --- '.$e->getTraceAsString());
}
}
}
function copyrows($id)
{
$this->load->model('customer_model','customers');
$this->load->model('standby_model','standby');
$this->customers->insert($id); //insert into another table first
$this->standby->delete($id); //then you can delete the source
}
inside my folder model
customer_model.php
<?php
class Customer_model extends CI_Controller
{
public function insert($id) {
$this->db->where('id_standby',$id);
$rs = $this->db->get('standby')->result_array();
$data['id_standby'] = $rs['id_standby'];
$data['name'] = $rs['name'];
$data['email'] = $rs['email'];
$data['address'] = $rs['address'];
$data['phone'] = $rs['phone'];
$data['password'] = $rs['password'];
$this->db->insert('customers', $data);
}
}
?>
and standby_model.php
<?php
class Standby_model extends CI_Controller
{
public function delete($id){
$this->db->delete('standby', array('id_standby'=>$id));
}
}
?>
Posted 07 February 2013 - 21:57 PM
Posted 07 February 2013 - 21:58 PM
Posted 07 February 2013 - 22:00 PM
Posted 07 February 2013 - 22:02 PM
Hi Victor!
Table Customers
id_custumer
Table Standby
id_standby
the rest of fields are the same in both tables
name, email, address, phone, so on...
Posted 07 February 2013 - 22:03 PM
Posted 07 February 2013 - 22:08 PM
no, the id for customers table is id_customer, there is not a column called id_standby in this table
Posted 07 February 2013 - 22:13 PM
your mistake is here:
<?php
class Customer_model extends CI_Controller
{
.......
$data['id_standby'] = $rs['id_standby'];
..........
$this->db->insert('customers', $data);
}
}
?>
You want to insert a wrong data into table "'customers" . $data['id_standby'] - is field name. But you haven't this column in your table
Posted 07 February 2013 - 22:17 PM
I want to copy a row from standby to customers
I changed this $data['id_customer'] = $rs['id_customer']; but it's not working
<?php
class Customer_model extends CI_Controller
{
public function insert($id) {
$this->db->where('id_standby',$id);
$rs = $this->db->get('standby')->result_array();
$data['id_customer'] = $rs['id_customer'];
$data['name'] = $rs['name'];
$data['email'] = $rs['email'];
$data['address'] = $rs['address'];
$data['phone'] = $rs['phone'];
$data['password'] = $rs['password'];
$this->db->insert('customers', $data);
}
}
?>
Posted 07 February 2013 - 22:21 PM
post deleted
Posted 07 February 2013 - 22:23 PM
what error do you have?
is this first project for you?
Posted 07 February 2013 - 22:24 PM
I deleted that row $data['id_customer'] = $rs['id_customer']; but doens't work, no insert the row.
Posted 07 February 2013 - 22:25 PM
there is no error, just the insert doesn't work.
and yes, it's my first proyect.
Posted 07 February 2013 - 22:28 PM
did u try it in your server? it's working?
Posted 07 February 2013 - 22:33 PM
no , I don't try. I see that you haven't result after:
$this->db->where('id_standby',$id);
$rs = $this->db->get('standby')->result_array();
the $rs is NULL
then you try insert an empty row.
P.S.
Try make for example blog without third party libraries. You don't know how to debug your code.
http://blog.teamtreehouse.com/how-to-debug-in-php
Posted 07 February 2013 - 22:38 PM
Posted 07 February 2013 - 22:45 PM
I changed the id, now both tables have a column id like the original example who j-gun wrote, but still not working.
Thanks for your help!
Posted 07 February 2013 - 22:50 PM
send me a private message with your controller and database dump . I try help you. But it will be tomorrow