[SOLVED] delete row - El Forum - 02-15-2010
[eluser]maria clara[/eluser]
hi to all,
i was able to delete the data but when i refreshed the page the data was coming back.. how can i delete it and not come back when i refresh the page???
here's my CONTROLLER:
Code: case $crudConfig['delete']:
$this->db->where('company_id', $this->input->post('id'));
$this->db->delete_detail($crudTableName);
break;
my MODEL:
Code: function delete_detail($data) //Query function use to delete user
{
$deleted_row = $data['company_code'];
$data['is_deleted'] = '1';
$this->db->where('company_id', $data['company_id']);
$this->db->update('maint_company', $data);
/*$this->db->where('user_id', $id['user_id']);
$this->db->update('sec_companyaccess', $id);*/
return $deleted_row;
}
hope anyone can help me,
thanks in advance,
EDIT:
I have to delete the company_id in both maint_company and sec_companyaccess tables
[SOLVED] delete row - El Forum - 02-15-2010
[eluser]theprodigy[/eluser]
Quote:Code: case $crudConfig['delete']:
$this->db->where('company_id', $this->input->post('id'));
$this->db->delete_detail($crudTableName);
break;
Why are you calling the delete_detail method on the db and not on the model?
Quote:Code: function delete_detail($data) //Query function use to delete user
{
$deleted_row = $data['company_code'];
$data['is_deleted'] = '1';
$this->db->where('company_id', $data['company_id']);
$this->db->update('maint_company', $data);
/*$this->db->where('user_id', $id['user_id']);
$this->db->update('sec_companyaccess', $id);*/
return $deleted_row;
}
If you need to delete out of both tables, why is the second table commented out?
(I hope this one doesn't turn into another 7 page thread :lol: )
[SOLVED] delete row - El Forum - 02-15-2010
[eluser]maria clara[/eluser]
hi, i have noticed the call to undefined method :: delete_detail so i already changed it.
MODEL:
Code: function delete($data) //Query function use to delete user
{
$deleted_row = $data['company_code'];
$data['is_deleted'] = '1';
$this->db->where('company_id', $data['company_id']);
$this->db->update('maint_company', $data);
$this->db->where('user_id', $id['user_id']);
$this->db->update('sec_companyaccess', $id);
return $deleted_row;
}
CONTROLLER:
Code: case $crudConfig['delete']:
$this->db->where('company_id', $this->input->post('id'));
$this->db->delete($crudTableName);
break;
NOTE:
yes i hope this will not go up to page 8. :lol:
it was deleting at first but when i refreshed the page the one i deleted comes back in..how can i delete it the right way???
[SOLVED] delete row - El Forum - 02-15-2010
[eluser]theprodigy[/eluser]
[quote author="maria clara" date="1266314522"]hi, i have noticed the call to undefined method :: delete_detail so i already changed it.
MODEL:
Code: function delete($data) //Query function use to delete user
{
$deleted_row = $data['company_code'];
$data['is_deleted'] = '1';
$this->db->where('company_id', $data['company_id']);
$this->db->update('maint_company', $data);
$this->db->where('user_id', $id['user_id']);
$this->db->update('sec_companyaccess', $id);
return $deleted_row;
}
CONTROLLER:
Code: case $crudConfig['delete']:
$this->db->where('company_id', $this->input->post('id'));
$this->db->delete($crudTableName);
break;
NOTE:
yes i hope this will not go up to page 8. :lol:
it was deleting at first but when i refreshed the page the one i deleted comes back in..how can i delete it the right way???[/quote]
Ok, once again, in your controller, why are you calling it on db, and not the model name?
Your Controller needs something like:
Code: $this->load->model('[MODEL_NAME]'); // if the model isn't already loaded
$this->MODEL_NAME->delete($crudTableName);
As it is right now, you are calling it on the db and not ever touching your model. It told you that the function doesn't exist, because CI's db class doesn't have a function by that name. Changing the method name to delete, won't necessarily throw an error, because it contains a delete method. You are having your controller do what the model should be doing.
[SOLVED] delete row - El Forum - 02-15-2010
[eluser]maria clara[/eluser]
i did what you've said
Code: $this->User->delete($CrudTableName); // User is my model that is being loaded in my controller
function delete($data) //function in my model that is being called
{
$deleted_row = $data['company_code'];
//$data['is_deleted'] = '1';
$this->db->where('company_id', $data['company_id']);
$this->db->update('maint_company', $data);
$this->db->where('user_id', $data['user_id']);
$this->db->update('sec_companyaccess', $data);
return $deleted_row;
}
but i got a database errors:
Quote:A Database Error Occurred
<p>Error Number: 1054</p><p>Unknown column 'erp_maint_company' in 'field list'</p><p>UPDATE `erp_maint_company` SET `erp_maint_company` = '' WHERE `company_id` = '51' AND `company_id` = 'e'</p>
[SOLVED] delete row - El Forum - 02-15-2010
[eluser]theprodigy[/eluser]
are you deleting the row (hard delete) or updating a boolean flag (soft delete)?
[SOLVED] delete row - El Forum - 02-15-2010
[eluser]maria clara[/eluser]
[quote author="theprodigy" date="1266321036"]are you deleting the row (hard delete) or updating a boolean flag (soft delete)?[/quote]
i am doing this:
deleting the row (hard delete)
but i think the $CrudTableName affects it and that's why it shows me a database error like this
Code: Unknown column 'erp_maint_company' in 'field list'</p><p>UPDATE `erp_maint_company` SET `erp_maint_company` = '' WHERE `company_id` = '51' AND `company_id` = 'e'</p>
because i have set this above my function in my controller:
Code: $crudColumns = array(
'id'=>'company_id'
,'company_code'=>'company_code'
,'company_name'=>'company_name'
);
$crudTableName = 'erp_maint_company'; //<------ i have set the table name
$postConfig['id'] = 'company_id';
[SOLVED] delete row - El Forum - 02-16-2010
[eluser]theprodigy[/eluser]
Quote:function delete($data) //function in my model that is being called
{
$deleted_row = $data['company_code'];
//$data['is_deleted'] = '1';
$this->db->where('company_id', $data['company_id']);
$this->db->update('maint_company', $data);
$this->db->where('user_id', $data['user_id']);
$this->db->update('sec_companyaccess', $data);
return $deleted_row;
}
Quote:Unknown column 'erp_maint_company' in 'field list'</p><p>UPDATE `erp_maint_company` SET `erp_maint_company` = '' WHERE `company_id` = '51' AND `company_id` = 'e'</p>
The reason I was asking is because your DELETE function is calling an UPDATE query.
Show me the controller and model code (only the relevant code, I don't need to FULL controller and model). I want to see how you changed them.
[SOLVED] delete row - El Forum - 02-16-2010
[eluser]maria clara[/eluser]
here is my controller (it is in switch but i will just show you the delete case):
Code: function detailpost()
{
$crudColumns = array(
'id'=>'company_id'
,'company_code'=>'company_code'
,'company_name'=>'company_name'
);
$crudTableName = 'erp_maint_company';
$postConfig['id'] = 'company_id';
$postConfig['action'] = 'oper'; /* action variable */
keyword *//* set to be the same as action keyword for default */
$crudConfig['create'] = 'add'; /* action CREATE keyword */
$crudConfig['update'] = 'edit'; /* action UPDATE keyword */
$crudConfig['delete'] = 'del'; /* action DELETE keyword */
$crudConfig['totalPages'] = 'total'; /* total pages */
$crudConfig['totalRecords'] = 'records'; /* total records */
foreach ($postConfig as $key => $value){
if(isset($_REQUEST[$value])){
$postConfig[$key] = fnCleanInputVar($_REQUEST[$value]);
}
/*some other case statement here*/
case $crudConfig['delete']:
#print_r($_POST);
$this->db->where('company_id', $this->input->post('id'));
$this->User->delete($crudTableName);
//$this->db->delete($crudTableName);
}
here's my model (will show you just the function concerning the delete)
Code: function delete($data) //Query function use to delete user
{
$deleted_row = $data['company_code'];
//$data['is_deleted'] = '1';
$this->db->where('company_id', $data['company_id']);
$this->db->update('maint_company', $data); //<------ even if i use the set in replace of update
$this->db->where('user_id', $data['user_id']);
$this->db->update('sec_companyaccess', $data); //<------ even if i use the set in replace of update
return $deleted_row;
}
[SOLVED] delete row - El Forum - 02-16-2010
[eluser]theprodigy[/eluser]
Change:
Code: case $crudConfig['delete']:
#print_r($_POST);
$this->db->where('company_id', $this->input->post('id'));
$this->User->delete($crudTableName);
//$this->db->delete($crudTableName);
}
to:
Code: case $crudConfig['delete']:
#print_r($_POST);
$data['table_name'] = $crudTableName;
$data['company_id'] = $this->input->post('id'); // and make sure you are posting this data
$data['user_id'] = $this->input->post('user_id'); // and make sure you are posting this data
$this->User->delete($data); //<----- You need to pass the company data, the user id, and the table name to the query
}
Change:
Code: function delete($data) //Query function use to delete user
{
$deleted_row = $data['company_code'];
//$data['is_deleted'] = '1';
$this->db->where('company_id', $data['company_id']);
$this->db->update('maint_company', $data); //<------ even if i use the set in replace of update
$this->db->where('user_id', $data['user_id']);
$this->db->update('sec_companyaccess', $data); //<------ even if i use the set in replace of update
return $deleted_row;
}
to:
Code: function delete($data) //Query function use to delete user
{
$deleted_row = $data['company_code'];
//$data['is_deleted'] = '1';
$this->db->where('company_id', $data['company_id']);
$this->db->delete('maint_company'); // need to DELETE, not UPDATE
$this->db->where('user_id', $data['user_id']);
$this->db->where('company_id', $data['company_id']); // need this field too or you will delete ALL the companies associated with the user
$this->db->delete('sec_companyaccess'); // need to DELETE, not UPDATE
return $deleted_row; // why are you returning this, and what are you returning it to?
}
I can't guarantee that this will work, but it's at least a very good head start. This should get you moving in the right direction.
Take a look at what I did, and change your code accordingly. As for me, I'm heading off to bed. I will look at future postings tomorrow after work (or someone else can take a look at them too ).
|