Multiple records to Google Charts


I would like to make a timeline from a SQL query with the help of Google Charts. I have used the following code to create the array, that encode to json. The problem is, that $table contains only the last record on the end of this code, but I have more than 1 record.

$rows = array(); $table = array(); $table['cols'] = array( array('id' => '', 'label' => 'Name', 'pattern' => '', 'type' => 'string'), array('id' => '', 'label' => 'Start', 'pattern' => '', 'type' => 'date'), array('id' => '', 'label' => 'End', 'pattern' => '', 'type' => 'date') ); while($r = mysql_fetch_assoc($results)) { $name=$r['Name']; $date=$r['Date']; $start=$r['start']; $end=$r['end']; $year=date("Y", strtotime($date)); $month=date("m", strtotime($date)); $day=date("d", strtotime($date)); $start_h=date("H", strtotime($start)); $start_min=date("i", strtotime($start)); $start_sec=date("s", strtotime($start)); $end_h=date("H", strtotime($end)); $end_min=date("i", strtotime($end)); $end_sec=date("s", strtotime($end)); $start_merged = "Date(".$year.",".$month.",".$day.",".$start_h.",".$start_min.",".$start_sec.")"; $end_merged = "Date(".$year.",".$month.",".$day.",".$end_h.",".$end_min.",".$end_sec.")"; $rows = array(); $temp = array(); $temp[] = array('v' => (string) $name); $temp[] = array('v' => (string) $start_merged); $temp[] = array('v' => (string) $end_merged); $rows[] = array('c' => $temp); } $table['rows'] = $rows;


You empty the array in which you collect the results in the middle of the loop:

$rows = array();

Move it outside.

Disclaimer: I haven't checked the rest of the code.

Note: judicious use of var_dump or print_r can quickly show you where the problem occours.


  • How to count spring coil turns?
  • Referring to individual variables in … with dplyr quos
  • Refresh other frame, from another frame. Jquery
  • xcode don't localize specific strings
  • Why use database factory in asp.net mvc?
  • Is playing sound in Javascript performance heavy?
  • Swift: Switch statement fallthrough behavior
  • Debugging ASP.NET on a built-in web server suddenly stops
  • Insert into database using onclick function
  • Illegal mix of collations for operation for date/time comparison
  • java.lang.NoClassDefFoundError: com.parse.Parse$Configuration$Builder on below Lollipop versions
  • WinForms: two way TextBox problem
  • Knitr HTML Loop - Some HTML output, some R output
  • Which linear programming package should I use for high numbers of constraints and “warm starts” [clo
  • How to set my toolbar fixed while scrolling android
  • Can a Chrome extension content script make an jQuery AJAX request for an html file that is itself a
  • Release, debug version and Authorization Google?
  • R: gsub and capture
  • AT Commands to Send SMS not working in Windows 8.1
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • How to delete a row from a dynamic generate table using jquery?
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • json Serialization in asp
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • python regex in pyparsing
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Hits per day in Google Big Query
  • What are the advantages and disadvantages of reading an entire file into a single String as opposed
  • How do I configure my settings file to work with unit tests?
  • How to stop GridView from loading again when I press back button?
  • Android Google Maps API OnLocationChanged only called once
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • apache spark aggregate function using min value
  • Sorting a 2D array using the second column C++
  • Binding checkboxes to object values in AngularJs
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • How can I use threading to 'tick' a timer to be accessed by other threads?