<p>NOT TESTED</p>

<ol>
<li>I think you can just add an array to gistDistribution, it will get
json_encoded before saving.</li>
<li><p>I think you'd have to set the variable like this:</p>

<p><code>$arr[0] = array(...);</code></p></li>
</ol>

<p>That way, you provide a multidimensional array, which is what a table needs.</p>

CC BY-SA 3.0
2014-11-21T00:13:42.780Z
I have tested your recommendations. It works. To add a row. 
$arr[0] = array(...);
$existingDistributions = $entry->getContent()->gistDistribution;
array_push($existingDistributions, $arr[0]);
David A McInnis
CC BY-SA 3.0
2014-11-20T21:05:47.777Z
2014-11-20T21:05:47.777Z
Paul
<p>I keep getting a server error when attempting to save data to a table field. This is the code I am using test data insertion. (251 is a valid enteryId)</p>

<pre><code>    $entry = craft()-&gt;entries-&gt;getEntryById(251, $localeId = null);
    $arr = array('col1' =&gt; 'some sku', 'col2' =&gt; 'This is a big fat description', 'col3' =&gt; 495.00, 'col4' =&gt; 0);
    $arr = json_encode($arr);
    $entry-&gt;getContent()-&gt;gistDistribution = $arr;
    $success = craft()-&gt;entries-&gt;saveEntry($entry);
</code></pre>

<p>This is my error:</p>

<pre><code>Internal Server Error
Illegal string offset 'sku'
</code></pre>

<p>Note: sku is a column name in my table field.</p>

<plugin-development><table-field>
Saving to Table Field Type via Plugin
# Saving to Table Field Type via Plugin

(Asked by: username_0 on 2014-11-20)

I keep getting a server error when attempting to save data to a table field. This is the code I am using test data insertion. (251 is a valid enteryId)
    $entry = craft()->entries->getEntryById(251, $localeId = null);
    $arr = array('col1' => 'some sku', 'col2' => 'This is a big fat description', 'col3' => 495.00, 'col4' => 0);
    $arr = json_encode($arr);
    $entry->getContent()->gistDistribution = $arr;
    $success = craft()->entries->saveEntry($entry);

This is my error:
Internal Server Error
Illegal string offset 'sku'

Note: sku is a column name in my table field.

**Tags:** plugin-development, table-field


---

## 1 answers

### Answer by username_1 on 2014-11-20. Score: 3 | Accepted answer

NOT TESTED

1. I think you can just add an array to gistDistribution, it will get
   json\_encoded before saving.
2. I think you'd have to set the variable like this:

   `$arr[0] = array(...);`

That way, you provide a multidimensional array, which is what a table needs.

> **Comments:**
> **username_0**: I have tested your recommendations. It works. To add a row.  $arr[0] = array(...); $existingDistributions = $entry->getContent()->gistDistribution; array_push($existingDistributions, $arr[0]);  

---

