title: Saving and read json_encode from database text field
body: <p>I am trying to make chart for product detail page visit report, 1 row represent 1 day and increment for every visit for the same day. This script is part of, and actually it works :</p>
  
  <pre><code>var chartData = []; 
  
  chartData  = &lt;?php echo json_encode($array); ?&gt;; // array from db query
  
  var chart = AmCharts.makeChart("chartdiv", { //.... and so on..
  </code></pre>
  
  <p>For some reason that 'I think' it would be so many rows for many products, So I just want to use a single row of table text field to store and hold data for one month period in JSON format. It means 1 row can store +/- 30 information.</p>
  
  <p>I tried to store the json_encode object in database text field with ajax and JSON.stringify(). The stored data in text field is like this :</p>
  
  <pre><code>[{"date":"2018-06-24","visits":"510"},{"date":"2018-06-25","visits":"511"},
  {"date":"2018-06-26","visits":"500"},{"date":"2018-06-27","visits":"508"},
  {"date":"2018-06-28","visits":"509"}]
  </code></pre>
  
  <p>When I query this row, it returns array rather than a string. By using print_r() it return :</p>
  
  <pre><code>Array ( [data] =&gt; [{"date":"2018-06-24","visits":"510"},{"date":"2018-06-25","visits":"511"},{"date":"2018-06-26","visits":"500"},{"date":"2018-06-27","visits":"508"},{"date":"2018-06-28","visits":"509"}] [0] =&gt; [{"date":"2018-06-24","visits":"510"},{"date":"2018-06-25","visits":"511"},{"date":"2018-06-26","visits":"500"},{"date":"2018-06-27","visits":"508"},{"date":"2018-06-28","visits":"509"}] ) 
  </code></pre>
  
  <p>Questions :</p>
  
  <ol>
  <li><p>How to fetch this data that stored in database and return it to JavaScript object. Why it returns an array rather than a string. I use json_decode() but it required a string. It was fail to use JSON.parse() to parse the data.</p></li>
  <li><p>Is that a right way to do it so?</p></li>
  </ol>
  
  <p>Any answer is appreciated. </p>