Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] delete row
#11

[eluser]maria clara[/eluser]
i think it was not deleting. because as i look at the table where i data is located, it is still there. And i think the code is not working. :-(
#12

[eluser]theprodigy[/eluser]
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');
echo $this->db->last_query(); //<----- put this here    
        $this->db->where('user_id', $data['user_id']);
        $this->db->where('company_id', $data['company_id']);
        $this->db->delete('sec_companyaccess');
echo $this->db->last_query(); //<----- put this here        
        return $deleted_row;
    }
Add those two lines of code in your model. If the output is not what you expect, post the output of those two lines, and the code from your controller and model.
#13

[eluser]maria clara[/eluser]
when i have the
Code:
$this->db->where('user_id', $data['user_id']);
in my MODEL delete function i got this message from my console

Quote:DELETE FROM `erp_maint_company`
WHERE `company_id` = '47'
AND `company_id` = '47'

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message: Undefined index: user_id</p> <-------- user_id shows undefined
<p>Filename: models/users_db.php</p>
<p>Line Number: 307</p>

</div>DELETE FROM `erp_sec_companyaccess`
WHERE `user_id` IS NULL <---------- and it is NULL
AND `company_id` = '47'
AND `company_id` = '47'{"company_id":"47"}

maybe because im trying to delete the company_id only from the maint_company and sec_companyaccess table.

but when i commented the
Code:
//$this->db->where('user_id', $data['user_id']);
it shows me no undefined index for user_id. but when i click the refresh button in the jqgrid, the one i deleted shows up again and the records becomes 10 again instead of 9. i have 10 records.

EDIT:

Quote:DELETE FROM `erp_maint_company`
WHERE `company_id` = '48'
AND `company_id` = '48'DELETE FROM `erp_sec_companyaccess`
WHERE `company_id` = '48'
AND `company_id` = '48'{"company_id":"48"}

in this, it shows that it is deleted but actually it is not. it will be just deleted if i will delete it straight in the table where it is located.

i attached images for you to see.
#14

[eluser]theprodigy[/eluser]
show me your model code please
#15

[eluser]maria clara[/eluser]
[quote author="theprodigy" date="1266487932"]show me your model code please[/quote]

here is my model

Code:
function delete($data) //Query function use to delete detail user
    {
        #$deleted_row = $data['company_code'];
        
        //$data['maint_company.is_deleted'] = '1';
        $this->db->where('company_id', $data['company_id']);
        $this->db->update('maint_company',$data); // need to DELETE, not UPDATE
        //echo $this->db->last_query(); //<----- put this here  
        //$this->db->where('user_id', $data['user_id']);
        //$this->db->where('company_id', $data['company_id']); //need this field too or will delete ALL the companies associated with the user
        $this->db->update('sec_companyaccess', $data); // need to DELETE, not UPDATE
        echo $this->db->last_query(); //<----- put this here  
        #return $deleted_row;
    }


controller

Code:
case $crudConfig['delete']:  // kaht code -deleting but have error
                //$data['table_name'] = $crudTableName;
                $data['company_id'] = $this->input->post('id'); // and make sure are posting this data
                //$data['user_id'] = $this->input->post('user_id'); // and make sure are posting this data
                $this->User->delete($data); //<----- need to pass the company data, the user id, and the table name to the query

        /*    case $crudConfig['delete']:
                $this->db->where('company_id', $this->input->post('id'));
                #$this->User->delete($crudTableName);
                $this->db->delete($crudTableName);*/
            }
#16

[eluser]theprodigy[/eluser]
Quote:here is my model
Code:
function delete($data) //Query function use to delete detail user
    {
        #$deleted_row = $data['company_code'];
        
        //$data['maint_company.is_deleted'] = '1';
        $this->db->where('company_id', $data['company_id']);
        $this->db->update('maint_company',$data); // need to DELETE, not UPDATE
        //echo $this->db->last_query(); //<----- put this here  
        //$this->db->where('user_id', $data['user_id']);
        //$this->db->where('company_id', $data['company_id']); //need this field too or will delete ALL the companies associated with the user
        $this->db->update('sec_companyaccess', $data); // need to DELETE, not UPDATE
        echo $this->db->last_query(); //<----- put this here  
        #return $deleted_row;
    }
OK, first off, why are you calling the UPDATE function? You should be calling the DELETE function to delete the records.
Also, you don't need to pass the $data array to the delete function as you are setting the where clause right above it.
Quote:controller
Code:
case $crudConfig['delete']:  // kaht code -deleting but have error
                //$data['table_name'] = $crudTableName;
                $data['company_id'] = $this->input->post('id'); // and make sure are posting this data
                //$data['user_id'] = $this->input->post('user_id'); // and make sure are posting this data
                $this->User->delete($data); //<----- need to pass the company data, the user id, and the table name to the query

        /*    case $crudConfig['delete']:
                $this->db->where('company_id', $this->input->post('id'));
                #$this->User->delete($crudTableName);
                $this->db->delete($crudTableName);*/
            }
Quote: DELETE FROM `erp_maint_company`
WHERE `company_id` = ‘47’
AND `company_id` = ‘47’
A PHP Error was encountered

Severity: Notice
Message: Undefined index: user_id <————user_id shows undefined
Filename: models/users_db.php
Line Number: 307

</div>DELETE FROM `erp_sec_companyaccess`
WHERE `user_id` IS NULL <—————and it is NULL //because you aren't passing in the user_id to the function. You commented out that line.
AND `company_id` = ‘47’
AND `company_id` = ‘47’{“company_id”:“47”}
#17

[eluser]maria clara[/eluser]
i fixed my code. but i have this in my console, a database error.

Quote:Unknown column 'user_id' in 'where clause'</p><p>DELETE FROM `erp_maint_company`
WHERE `company_id` = '73'
AND `company_id` = '73'
AND `user_id` = 0

here's my code now:

MODEL:

Code:
function delete($data) //Query function use to delete detail user
    {
        //$deleted_row = $data['company_code'];
        
        //$data['maint_company.is_deleted'] = '1';
        $this->db->where('company_id', $data['company_id']);
        $this->db->delete('maint_company',$data); // need to DELETE, not UPDATE
        echo $this->db->last_query();
        $this->db->where('user_id', $data['user_id']);
        $this->db->where('company_id', $data['company_id']); // need this field too or will delete ALL the companies associated with the user
        $this->db->delete('sec_companyaccess', $data); // need to DELETE, not UPDATE
        echo $this->db->last_query();
        //return $deleted_row;
    }

CONTROLLER:

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); //<----- need to pass the company data, the user id, and the table name to the query
                
                /*#print_r($_POST);
                $this->db->where('company_id', $this->input->post('id'));
                //$this->User->delete($crudTableName);
                $this->db->delete($crudTableName);*/
            }


i just coded like what you have said before.

EDIT:
when i take out the $data in the function delete($data) there will show me an undefined variable for all of my $data in the model
#18

[eluser]cahva[/eluser]
You dont need to pass $data array to the delete in the first deletion(where you delete company first). Same goes for the other one. Dont give any attributes to the delete as you are already using $this->db->where:
Code:
// Below equals DELETE FROM maint_company WHERE company_id = [company_id]
$this->db->where('company_id', $data['company_id']);
$this->db->delete('maint_company');

// Below equals DELETE FROM sec_companyaccess WHERE user_id = [user_id] AND company_id = [company_id]
$this->db->where('user_id', $data['user_id']);
$this->db->where('company_id', $data['company_id']);
$this->db->delete('sec_companyaccess');
#19

[eluser]maria clara[/eluser]
@cahva,

hi, do you mean i should take the $data in this
Code:
function delete($data) //<-- $data here
. i tried to remove it but it show me this messages in my console:


<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message: Undefined variable: data</p>
<p>Filename: models/users_db.php</p>
<p>Line Number: 305</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

Quote:<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message: Undefined variable: data</p>
<p>Filename: models/users_db.php</p>
<p>Line Number: 309</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message: Undefined variable: data</p>
<p>Filename: models/users_db.php</p>
<p>Line Number: 310</p>

</div>{"table_name":"erp_maint_company","company_id":"75"}<br />


thanks for reply
#20

[eluser]cahva[/eluser]
Do not remove it from function attribute. Remove it from $this->db->delete
Code:
// original
$this->db->delete('maint_company',$data);

// remove $data
$this->db->delete('maint_company');

Same goes for the other $this->db->delete




Theme © iAndrew 2016 - Forum software by © MyBB