Answers.Body: <p>When saving data to a Table field, here's the catch... Your field data is being condensed into <strong>JSON</strong> and stored in a <strong>single database table cell</strong>.</p>
  
  <p>So ultimately, you'll want to have your Table field data arranged in an array, then use <code>json_encode</code> to prep it for entry into the database.</p>
  
  <p>Here's an example of data for a Table field... This is a hypothetical field containing products, with a <em>Product Name</em> and prices for <em>Small</em>, <em>Medium</em>, and <em>Large</em>...</p>
  
  <pre><code>[
    {
      "col1": "Product #1",
      "col2": "5",
      "col3": "10",
      "col4": "15"
    },
    {
      "col1": "Product #2",
      "col2": "7",
      "col3": "14",
      "col4": "21"
    },
    {
      "col1": "Product #3",
      "col2": "7",
      "col3": "14",
      "col4": "21"
    }
  ]
  </code></pre>
  
  <p><strong>An important note...</strong> The column names you established when setting up your Table field are not relevant here. Instead, each columnn will be referred to as "col1", "col2", "col3", etc.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-09T15:38:24.773Z
Answers.Text: Is this still a viable solution? I'm using similare json structure but it doesn't work.
Answers.UserDisplayName: Alessio Breviglieri
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-09T23:15:19.567Z
Answers.Text: Yes, this should still work. If you are having a similar issue, I recommend you [ask a new question...](https://craftcms.stackexchange.com/questions/ask)
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-07T13:23:05.403Z
Answers.Text: Just a note in case anyone finds this - you do not want to use `json_encode` - use the actual array to set the value.
Answers.UserDisplayName: Dan Ott
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-23T01:46:51.570Z
Answers.LastActivityDate: 2014-07-23T01:46:51.570Z
Answers.UserDisplayName: Lindsey D
Body: <p>I now know that you can enter data into an entry's field by using <code>$event-&gt;params['entry']-&gt;getContent()-&gt;handle</code> </p>
  
  <p>But let's say I have a foreach loop and I want to enter each line into an entry that is a table field. So for example:</p>
  
  <pre><code>foreach ($apigrab['properties'] as $specs) {
      $event-&gt;params['entry']-&gt;getContent()-&gt;specs == ??
  }
  </code></pre>
  
  <p>Obviously each table heading has it's own handle and I don't imagine specs.handle would work in this case, and also how would you prevent it from just overwriting the same line over and over again? Would I have to count how many first and tell it specifically where to go?</p>
  
  <p>Thanks in advance. </p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-18T01:11:12.550Z
Comments.Text: To clarify, are you saying that your "specs" field is a **table** field type?
Comments.UserDisplayName: Lindsey D
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-18T05:01:55.533Z
Comments.Text: @LindseyD Yep that's what I mean.
Comments.UserDisplayName: Chris
Tags: <plugin-development><entries>
Title: Programmatically entering data into a table field for an entry
ThreadText: # Programmatically entering data into a table field for an entry
  
  (Asked by: username_0 on 2014-07-17)
  
  I now know that you can enter data into an entry's field by using `$event->params['entry']->getContent()->handle`
  
  But let's say I have a foreach loop and I want to enter each line into an entry that is a table field. So for example:
  
  ```
  foreach ($apigrab['properties'] as $specs) {
      $event->params['entry']->getContent()->specs == ??
  }
  
  ```
  
  Obviously each table heading has it's own handle and I don't imagine specs.handle would work in this case, and also how would you prevent it from just overwriting the same line over and over again? Would I have to count how many first and tell it specifically where to go?
  
  Thanks in advance.
  
  **Tags:** plugin-development, entries
  
  > **Comments:**
  > **username_1**: To clarify, are you saying that your "specs" field is a **table** field type?  
  > **username_0**: @username_1 Yep that's what I mean.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-07-23. Score: 4 | Accepted answer
  
  When saving data to a Table field, here's the catch... Your field data is being condensed into **JSON** and stored in a **single database table cell**.
  
  So ultimately, you'll want to have your Table field data arranged in an array, then use `json_encode` to prep it for entry into the database.
  
  Here's an example of data for a Table field... This is a hypothetical field containing products, with a *Product Name* and prices for *Small*, *Medium*, and *Large*...
  
  ```
  [
    {
      "col1": "Product #1",
      "col2": "5",
      "col3": "10",
      "col4": "15"
    },
    {
      "col1": "Product #2",
      "col2": "7",
      "col3": "14",
      "col4": "21"
    },
    {
      "col1": "Product #3",
      "col2": "7",
      "col3": "14",
      "col4": "21"
    }
  ]
  
  ```
  
  **An important note...** The column names you established when setting up your Table field are not relevant here. Instead, each columnn will be referred to as "col1", "col2", "col3", etc.
  
  > **Comments:**
  > **username_2**: Is this still a viable solution? I'm using similare json structure but it doesn't work.  
  > **username_1**: Yes, this should still work. If you are having a similar issue, I recommend you [ask a new question...](https://craftcms.stackexchange.com/questions/ask)  
  > **username_3**: Just a note in case anyone finds this - you do not want to use `json_encode` - use the actual array to set the value.  
  
  ---
  
  