Welcome Guest, Not a member yet? Register   Sign In
Deletes are not allowed unless they contain a “where” or “like” clause
#1

[eluser]pakistanihaider[/eluser]
Getting Database Error.
Code:
Deletes are not allowed unless they contain a "where" or "like" clause.

Filename: C:\Apache24\htdocs\Projects\HouseRentSystem\system\database\DB_active_rec.php

Line Number: 1567

Also Posted the question on StackOverflow. Am I doing it the wrong way, if so then please tell the right way to delete data from database using both where and where_in conditions.

Question Posted On Stackoverflow

I dont know about forum rules moderator, if it is prohibited posting the stackoverflow link then surely you can delete the link, but please don't delete the question.

Here is my Code. i tried both ways.
1.
Code:
function multiple_delete($tbl,$field,$values,$where)
    {
        //$this->db;
        $this->db->where_in($field,$values)->delete($tbl,$where);
    }

2.
Code:
function multiple_delete($tbl,$field,$values,$where)
    {
        $this->db->where_in($field,$values);
        $this->db->delete($tbl,$where);
    }

Also tried like this.
Code:
function multiple_delete($tbl,$field,$values,$where)
    {
        $this->db->where();
        $this->db->where_in($field,$values);
        $this->db->delete($tbl);
        if ($this->db->affected_rows() > 0){
            return TRUE;
        }
        else {
            //return FALSE;
            return FALSE;
        }
    }

But no success so far.

Here is the data that i am sending.
Code:
$tbl = 'sys_forms_in_groups';
$field = 'FormID';
$value = $formIDsData;
$where = array(
    'GroupID' =>$groupID
);

$deleteResult = $this->Common_Model->multiple_delete($tbl,$field,$value,$where);

where $value has this array
Code:
Array ( [0] => 6 [1] => 7 [2] => 23 [3] => 41 )
and $groupID has a value of 2

Please tell how should i implement this query in codeigniter? i have found nothing in docs about this. Also Searched google.
#2

[eluser]larsonator[/eluser]
Taken from the Active Records Manual Page
Quote:The first parameter is the table name, the second is the where clause. You can also use the where() or or_where() functions instead of passing the data to the second parameter of the function

My guess is that the delete function doesnt utilise where_in.

I way to test this out is to write the following code after you use the delete function
Code:
echo "<pre>";
print_r($this->db);
echo "</pre>";
exit;
This will display the database object in as formatted text, One thing the database object does is store all previous sql statements called, from that you should be able to see if its using where_in or not.

possible work around would be
Code:
foreach($value as $v){
      $this->db->or_where($field, $v)
}




Theme © iAndrew 2016 - Forum software by © MyBB