Re: Error when display table data

69 views
Skip to first unread message

asgallant

unread,
Dec 3, 2012, 5:03:26 PM12/3/12
to google-visua...@googlegroups.com
Is this piece literally how it appears in Chrome?

data.setValue(0, 5, ' ');

If so, your output from "eta" is broken somehow.  Try doing a debug dump of $row['eta'] to see what is actually contained there.

On Monday, December 3, 2012 4:55:37 PM UTC-5, Tony Kehlhofer wrote:
I have a page that displays 5 columns of data. When I add a 6th column an error. I have tried several fixed based on the thought that my data was bad (addslashes, etc)

Here is the code that works:

                var data = new google.visualization.DataTable();
                data.addRows(<?php echo $howmany;?>);
                data.addColumn('string', 'Group', 'Group');
                data.addColumn('string', 'SKU', 'SKU');
                data.addColumn('string', 'Description', 'Description');
                data.addColumn('string', 'UOM', 'UOM');
                data.addColumn('number', 'Quantity', 'Quantity');
               
                <?php
                if ($howmany > 0)
                {
                    $counter = 0;
                    while($row = mysql_fetch_array($resultDlr))
                    {
                        echo 'data.setValue(' . $counter . ', 0, \'' . $row['prodgroup'] . '\');';
                        echo 'data.setValue(' . $counter . ', 1, \'' . $row['sku'] . '\');';
                        echo 'data.setValue(' . $counter . ', 2, \'' . addslashes($row['description']) . '\');';
                        echo 'data.setValue(' . $counter . ', 3, \'' . $row['uom'] . '\');';
                        echo 'data.setValue(' . $counter . ', 4, ' . $row['qty'] . ');';
                        $counter = $counter + 1;
                    }
                }
                ?>

                var table2 = new google.visualization.Table(document.getElementById('chart_divT'));

                var formatter = new google.visualization.NumberFormat(
                      {});
                  formatter.format(data, 4);

                table2.draw(data, {showRowNumber: false, width: '800px', page: 'enable', pageSize: 20, 'allowHtml': true, 'cssClassNames': cssClassNames});


when I add one column, the code is this, and it breaks:

                var data = new google.visualization.DataTable();
                data.addRows(<?php echo $howmany;?>);
                data.addColumn('string', 'Group', 'Group');
                data.addColumn('string', 'SKU', 'SKU');
                data.addColumn('string', 'Description', 'Description');
                data.addColumn('string', 'UOM', 'UOM');
                data.addColumn('number', 'Quantity', 'Quantity');
                data.addColumn('string', 'ETA', 'ETA');
               
                <?php
                if ($howmany > 0)
                {
                    $counter = 0;
                    while($row = mysql_fetch_array($resultDlr))
                    {
                        echo 'data.setValue(' . $counter . ', 0, \'' . $row['prodgroup'] . '\');';
                        echo 'data.setValue(' . $counter . ', 1, \'' . $row['sku'] . '\');';
                        echo 'data.setValue(' . $counter . ', 2, \'' . addslashes($row['description']) . '\');';
                        echo 'data.setValue(' . $counter . ', 3, \'' . $row['uom'] . '\');';
                        echo 'data.setValue(' . $counter . ', 4, ' . $row['qty'] . ');';
                        echo 'data.setValue(' . $counter . ', 5, \'' . $row['eta'] . '\');';
                        $counter = $counter + 1;
                    }
                }
                ?>

                var table2 = new google.visualization.Table(document.getElementById('chart_divT'));

                var formatter = new google.visualization.NumberFormat(
                      {});
                  formatter.format(data, 4);

                table2.draw(data, {showRowNumber: false, width: '800px', page: 'enable', pageSize: 20, 'allowHtml': true, 'cssClassNames': cssClassNames});


The only possible values from the db for field ETA are stored as strings:

NA
Jan 12, 2013
Dec 18, 2012
Dec 13, 2012
Dec 22, 2012
Dec 01, 2012
Dec 12, 2012

The error I get is:  Uncaught SyntaxError: Unexpected token ILLEGAL

and in Chrome, the source looks like this, showing that the first single quote around the first ETA is black and not red, which seems to be messing up the syntax of what I am writing out.


data.setValue(0, 0, 'CTOP');data.setValue(0, 1, 'PFBC-3096');data.setValue(0, 2, 'Prefinished Butcher Block');data.setValue(0, 3, 'PIECE');data.setValue(0, 4, 17.00);data.setValue(0, 5, ' ');

Please help !!

Tony

Tony Kehlhofer

unread,
Dec 3, 2012, 5:13:47 PM12/3/12
to google-visua...@googlegroups.com
Yes. I now put NA instead of space in the database for readability. here is the updated source from Chrome:

data.setValue(0, 0, 'CTOP');data.setValue(0, 1, 'PFBC-3096');data.setValue(0, 2, 'Prefinished Butcher Block');data.setValue(0, 3, 'PIECE');data.setValue(0, 4, 17.00);data.setValue(0, 5, 'NA');

So weird that the first quote is black when all previous ones are red

Tony Kehlhofer

unread,
Dec 3, 2012, 5:14:50 PM12/3/12
to google-visua...@googlegroups.com
Here is the result of "SELECT DISTINCT eta FROM inventory"

Edit Delete NA
Edit Delete Jan 12  2013
Edit Delete Dec 18  2012
Edit Delete Dec 13  2012
Edit Delete Dec 22  2012
Edit Delete Dec 01  2012
Edit Delete Dec 12  2012

asgallant

unread,
Dec 3, 2012, 5:36:04 PM12/3/12
to google-visua...@googlegroups.com
What does var_dump($row['eta']); output?

Tony Kehlhofer

unread,
Dec 3, 2012, 6:13:30 PM12/3/12
to google-visua...@googlegroups.com
it outputs  string(3) "NA
"


which is odd, since NA is length =2.  when I copy/paste the result to an editor, it seems as if a CR/LF is part if the output

For records that have data, I get string(12) "Jan 12  2013"  which IS length=12 and shows no indication of a CR/LF

Tony Kehlhofer

unread,
Dec 3, 2012, 6:17:29 PM12/3/12
to google-visua...@googlegroups.com
I now forced "No ETA avail" which is length = 12 into the database and it works !! ugh.... the string output is length = 12 and shows no indication of a CR/LF any more

asgallant

unread,
Dec 3, 2012, 6:40:59 PM12/3/12
to google-visua...@googlegroups.com
Glad to hear you got it working.  You can probably get rid of whatever that pesky character is by trimming the output from the database.
Reply all
Reply to author
Forward
0 new messages