Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Insert value JSON with foreach?

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #34971
    binboy
    Participant

    I use codeigniter. I want insert this value JSON to database, but with following PHP code it insert just [ in table. how can fix this problem?
    — i use mysql database and “var_dump($start_date,$percent);” output is as: ‘string(31) “[“2012/08/07″,”2011/10/29″]” array(1) { [0]=> string(2) “56” } [“2012/08/07″,”2011/10/29”]’

    Html code:




    This value JSON: [“2012/08/07″,”2011/10/29”]

    PHP code:

        $start_date         = json_encode($this->input->post('start_date'));
    $percent = $this->input->post('percent');

    print_r($start_date); // This output is as: ["2012/08/07","2011/10/29"]

    $data = array();
    foreach ($percent as $idx => $name) {
    $data[] = array(
    'start_date' => $start_date[$idx],
    'price_change' => $percent[$idx]
    );
    };
    $this->db->insert_batch('table', $data);
Viewing 1 post (of 1 total)
  • The forum ‘Back End’ is closed to new topics and replies.