string type unreachable by table chart

17 views
Skip to first unread message

drigo

unread,
May 21, 2019, 10:35:19 AM5/21/19
to Google Visualization API
Hi everybody, 

I am getting an odd behavior when I am trying to display a string column, called "Series Name", through a google table chart. 

You can find my php code below. Please note that if I drop the column "Series Name" everything works fine. Otherwise, the output table 
displays only the first 5 rows. Specifically, leaving the mentioned column if I set LIMIT >= 5 no table chart is created. 

Let me stress that this issue appears on a new VPS where php and mysql db have been installed. Same code works on my old VPS as expected. 

Any ideas how to overcome this issue?

Thanks in advance, 

Drigo


<?php

    try {
      /* Establish the database connection */
      $conn = new PDO("mysql:host=localhost;dbname=$dbname", $username, $password);
      $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

      /* select relevant info for table googlechart */
      $result_RTI_VS_W_TABLE = $conn->query("SELECT * FROM `video_series_rank_week` ORDER BY `Year` DESC, `WeekN` DESC, `Rank` ASC LIMIT 15");

      $rows_RTI_VS_W_TABLE = array();
      $table_RTI_VS_W_TABLE = array();
      $table_RTI_VS_W_TABLE['cols'] = array(

        /* Labels for your chart, these represent the column titles */
        array('label' => 'Rank', 'type' => 'number'),
        array('label' => 'Year', 'type' => 'string'),
        array('label' => 'WeekN', 'type' => 'number'),
        array('label' => 'Series Name', 'type' => 'string'),
        array('label' => 'Total Historical Constrained Ad Avails', 'type' => 'number')
    );
        /* Extract the information from $result */
        foreach($result_RTI_VS_W_TABLE as $r_RTI_VS_W_TABLE) {

        $temp_RTI_VS_W_TABLE = array();

       /* the following line will be used to get a table */
        $temp_RTI_VS_W_TABLE[] = array('v' => (int) $r_RTI_VS_W_TABLE['Rank']);

       /* Values */
        $temp_RTI_VS_W_TABLE[] = array('v' => (string) $r_RTI_VS_W_TABLE['Year']);
        $temp_RTI_VS_W_TABLE[] = array('v' => (int) $r_RTI_VS_W_TABLE['WeekN']);
        $temp_RTI_VS_W_TABLE[] = array('v' => (string) $r_RTI_VS_W_TABLE['Series Name']);
        $temp_RTI_VS_W_TABLE[] = array('v' => (int) $r_RTI_VS_W_TABLE['Total Historical Constrained Ad Avails']);

        $rows_RTI_VS_W_TABLE[] = array('c' => $temp_RTI_VS_W_TABLE);}

        $table_RTI_VS_W_TABLE['rows'] = $rows_RTI_VS_W_TABLE;

    /* convert data into JSON format */
    $jsonTable_RTI_VS_W_TABLE = json_encode($table_RTI_VS_W_TABLE);
    } catch(PDOException $e) {echo 'ERROR: ' . $e->getMessage();}
    ?>

drigo

unread,
May 21, 2019, 5:34:18 PM5/21/19
to Google Visualization API
SOLVED
I had to add: 
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")

to my new PDO. 
Reply all
Reply to author
Forward
0 new messages