0

I am retrieving data from the database using a modal in Codeigniter, and when I pass the data to an array using foreach loop, It is giving the error.

Parse error: syntax error, unexpected ':', expecting ')' in D:\xampp\htdocs\base_codeigniter\application\controllers\User.php on line 32

I want to show the json data in a table in the View page.

What is wrong on the line 32

        foreach ($get_data as $data) {
        $show_table = array(
                             'name':$data['name'],  // Line 32
                             'email':$data['email'], // Line 33
                             'phone':$data['phone']
                        );
        echo json_encode($show_table);                

    }
Zim84
  • 3,404
  • 2
  • 35
  • 40
Ashwani Garg
  • 1,479
  • 1
  • 16
  • 22

2 Answers2

0

Your syntax is wrong:

$show_table = array(
    'name' => $data['name'],  // Line 32
    'email' => $data['email'], // Line 33
    'phone' => $data['phone']
);
Zim84
  • 3,404
  • 2
  • 35
  • 40
0

First thing - your syntax is wrong. It should be as suggested by @Ashwin Garg in the answer below, which is

$show_table = array(
    'name' => $get_data['name'],  // Line 32
    'email' => $get_data['email'], // Line 33
    'phone' => $get_data['phone']
);

Second issue is that you should use get_data variable inside the loops which represent the current object. $data is the iterable object that you want to loop through not the individual element of that object.

Robin
  • 32
  • 3