Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9152651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:06:30+00:00 2026-06-17T12:06:30+00:00

I want to load the data from a JSON file into a table. (With

  • 0

I want to load the data from a JSON file into a table. (With Zend Framework)

This is my JSON file markup:

{
    "wijken": {
        "11": {
            "coords": "3.79073170001967,51.1717753664505,0 3.79020920176376,51.1723018883706,0 3.78989543642226,51.1729670713336,0 3.78983091856725,51.1736482209016,0 3.79035112720225,51.174896701853",
            "id": "kml_1",
            "fid": "0",
            "wijziging": "Ja",
            "nieuwnr": "11",
            "naam": "Noordoost",
            "wijk": "Kanaaldorpen en -zone",
            "wijknr": "11",
            "objectid": "1",
            "area": "0",
            "len": "0"
        }
}

I know how to do this with clear php: (and it works)

<?php
            //connection to database
            $$connect = mysql_connect('localhost', 'root', 'root');
            $db = mysql_select_db('testdatabase');

            // ALLE VELDEN LEEGMAKEN
            mysql_query("TRUNCATE TABLE wijken");

            // url from json file
            $url = "http://data.appsforghent.be/poi/wijken.json";

            //get content from json file
            $json = file_get_contents($url);

            // OM ALLES VAN IN DE JSON FILE TE TONENE
            //var_dump(json_decode($json));
            //var_dump(json_decode($json, true));

            $out = json_decode($json, true);


            foreach($out["wijken"] as $wijk) 
            {
                // ID + NAAM + WIJK + WIJKNR + COORDINATEN
                $coords = addslashes($wijk[coords]);
                $id = addslashes($wijk[id]);
                $fid = addslashes($wijk[fid]);
                $wijziging = addslashes($wijk[wijziging]);
                $nieuwnr = addslashes($wijk[nieuwnr]);
                $naam = addslashes($wijk[naam]);
                $wijk = addslashes($wijk[wijk]);
                $wijknr = addslashes($wijk[wijknr]);
                $objectid = addslashes($wijk[objectid]);
                $area = addslashes($wijk[area]);
                $len = addslashes($wijk[len]);

                mysql_query("INSERT INTO wijken (coords, id, fid, wijziging, nieuwnr, naam, wijk, wijknr, objectid, area, len) 
                             VALUES('$coords', '$id', '$fid', '$wijziging', '$nieuwnr', '$naam', '$wijk', '$wijknr', '$objectid', '$area', '$len')") or die (mysql_error());
            } 
        ?>

But how can I implement this in Zend Framework?
What I have till now in my models map in Zend Framework:

Map “DbTable” with Districts.php in it:

    class Backoffice_Model_DbTable_Districts extends Zend_Db_Table_Abstract
{
    protected $_name = 'Wijken';
}

District.php with getters and setters:

class Backoffice_Model_District extends Ahs_Model_Abstract
{
    protected $coords;

    protected $id;

    protected $fid;

    protected $wijziging;

    protected $nieuwnr;

    protected $naam;

    protected $wijk;

    protected $wijknr;

    protected $objectid;

    protected $area;

    protected $len;


    public function getCoords()
    {
        return $this->coords;
    }

    public function setCoords($coords)
    {
        $this->coords = $coords;
    }

    public function getId()
    {
        return $this->id;
    }

    public function setId($id)
    {
        $this->id = $id;
    }

    public function getFid()
    {
        return $this->fidid;
    }

    public function setFid($fid)
    {
        $this->fid = $fid;
    }

    public function getWijziging()
    {
        return $this->wijziging;
    }

    public function setWijziging($wijziging)
    {
        $this->wijziging = $wijziging;
    }

    public function getNieuwnr()
    {
        return $this->nieuwnr;
    }

    public function setNieuwnr($nieuwnr)
    {
        $this->nieuwnr = $nieuwnr;
    }

    public function getNaam()
    {
        return $this->naam;
    }

    public function setNaam($naam)
    {
        $this->naam = $naam;
    }

    public function getWijk()
    {
        return $this->wijk;
    }

    public function setWijk($wijk)
    {
        $this->wijk = $wijk;
    }

    public function getObjectid()
    {
        return $this->objectid;
    }

    public function setObjectid($objectid)
    {
        $this->objectid = $objectid;
    }

    public function getArea()
    {
        return $this->area;
    }

    public function setArea($area)
    {
        $this->area = $area;
    }

    public function getLen()
    {
        return $this->len;
    }

    public function setLen($len)
    {
        $this->len = $len;
    }


}

Now I have a DistrictMapper.php, but how can I implement the code to load everything from the json in my database?

What I have till now:

protected $_dbTable;

public function __construct()
{
    $this->_dbTable = new Backoffice_Model_DbTable_Districts();
}

public function fetchAll()
{
    $rowset = $this->_dbTable->fetchAll();

    $districts = $this->_toObjects($rowset);

    return $districts;
}

And now I need to make the save and toobject.

public function save(Backoffice_Model_Admin $admin)
    {
        $data = array('coords'  => $district->getCoords(),
                  'id' => $district->getId(),
                  'fid'      => $district->getFid(),
                  'wijziging'   => $district->getWijziging(),
                  'nieuwnr'   => $district->getNieuwnr(),
                  'naam'   => $district->getNaam(),
                  'wijk'   => $district->getWijk(),
                  'wijknr'   => $district->getWijknr(),
                  'objectid'   => $district->getObjectid(),
                  'area'   => $district->getArea(),
                  'len'   => $district->getLen(),
    );
    }

    protected function _toObject(Zend_Db_Table_Row_Abstract $row = null)
    {

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:06:31+00:00Added an answer on June 17, 2026 at 12:06 pm

    From the Zend docs, Zend_DbTable::insert(), and adapted to your other posted table info:

    public function save(Backoffice_Model_Admin $admin){ 
      $data = array(
        "fid": "0",
        "wijziging": "Ja",
        "nieuwnr": "11",
        // other data from $admin...
      );
      $table = new Backoffice_Model_DbTable_Districts();
      $table->insert($data);
    }
    

    Construct your array; pass it in.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to fetch data from JSON based on the employeeID. This is how
I want to load a JSON file from my own server containing an array
I want to load the data from 2 json files in my database. The
Is there any way to load data from a data file (eg a JSON
I want to load data from MySql database to a HTTP form When I
I have a form with a DataGridView and I want to load data from
I want to load the form fields using json data. I am using extjs
I want to load the list of the groups as well as data into
I want to load a data structure into a Ruby script which maps a
I am trying to populate a collection with data from a JSON file. I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.