1

I have posted values $a,$b,$c...are in array format model file i gave this.

 function insert_bank_data($da,$b,$c,$d,$e)
    {

        $data=array('date'=>$da,'des'=>$b,'amount'=>$c,'price'=>$d);
        $this->db->insert_batch('total_trans',$data);


}

I am getting an error like this.

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 '0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22' at line 1
4
  • Why are you used ; twice? Commented Dec 31, 2015 at 9:27
  • i removed it.still am nt getting Commented Dec 31, 2015 at 9:30
  • are $da,$b,$c,$d,$e arrays ? Commented Dec 31, 2015 at 9:31
  • yes. these are arrays.when i print_r($a)..i got '30-Dec-2015','30-Dec-2015','29-Dec-2015','28-Dec-2015','................................... Commented Dec 31, 2015 at 9:32

3 Answers 3

1

You can use json_encode()

function insert_bank_data($da,$b,$c,$d,$e)
{

    $data=array('date'=>json_encode($da),'des'=>json_encode($b),'amount'=>json_encode($c),'price'=>json_encode($d));
    $this->db->insert_batch('total_trans',$data);

}
Sign up to request clarification or add additional context in comments.

Comments

0

if arguments of the function are arrays of the same length you should write

function insert_bank_data($da,$b,$c,$d,$e)
{
  $data = array();
  for ($i-0; $i < count($da); $i++) {
    $data[] = array('date'=>$da[$i],'des'=>$b[$i],'amount'=>$c[$i],'price'=>$d[$i]);
  $this->db->insert_batch('total_trans',$data);
}

Comments

0

You can use this also...

function insert_bank_data($da,$b,$c,$d,$e)
{

    for ($i=0; $i < count($da); $i++) {
        $data= array('date'=>$da[$i],'des'=>$b[$i],'amount'=>$c[$i],'price'=>$d[$i]);
        $this->db->insert('total_trans',$data);
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.