2

I have where_in condition $this->db->where_in('student_id',$arr); Now I want to delete the contents present in $arr from a table using this code $this->db->delete('top_students'); But I got a database error

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 2 DELETE FROM top_students WHERE student_id IN()"

How to solve this?

Pradeep
  • 9,667
  • 13
  • 27
  • 34
Dishi
  • 41
  • 6

1 Answers1

1

Hope this will help you :

Check for empty like this ;

if ( ! empty($arr))
{
   $this->db->where_in('student_id',$arr);
   $this->db->delete('top_students'); 
}

For more : https://www.codeigniter.com/user_guide/database/query_builder.html#deleting-data

Pradeep
  • 9,667
  • 13
  • 27
  • 34