While I don't generally suggest building the DataTable like this (I find it
more productive to learn the JSON format and use that instead - you will be
happier down the road if/when you need to make a lot of charts pull from
your database), you can save yourself a bit of code and avoid some
potential problems here with a slightly different approach:
<?php
$con = mysql_connect("blabla","blabla","passwordblabla");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("robotfriend_org", $con);
$result = mysql_query("SELECT * FROM Users Order by fname ASC");
$output = array();
while($row = mysql_fetch_array($result)) {
// create a temp array to hold the data
$temp = array();
// add the data
$temp[] = '"' . $row['created_date'] . '"';
$temp[] = '"' . $row['fname'] . '"';
$temp[] = '"' . $row['lname'] . '"';
$temp[] = '"' . $row['country'] . '"';
$temp[] = '"' . $row['gender'] . '"';
$temp[] = '"' . $row['year'] . '"';
$temp[] = '"' . $row['month'] . '"';
$temp[] = '"' . $row['day'] . '"';
$temp[] = '"' . $row['email_encrypted'] . '"';
$temp[] = '"' . $row['password'] . '"';
// implode the temp array into a comma-separated list and add to the
output array
$output[] = '[' . implode(', ', $temp) . ']';
}
// implode the output into a comma-newline separated list and echo
echo implode(",\n", $output);
mysql_close($con);
?>
This avoids the problem of errant commas screwing up your code in IE. Use
it or don't.
On Saturday, June 16, 2012 10:34:24 AM UTC-4, anden1234 wrote:
>
> *I created users.php file and added the following code. DON'T forget to
>> add your own sql username/password and create a Users table in the
>> database!!:*
>>
>> <html>
>>
>> <head>
>>
>> <script type='text/javascript' src='https://www.google.com/jsapi
>> '></script>
>>
>> <script type='text/javascript'>
>>
>> google.load('visualization', '1', {packages:['table']});
>>
>> google.setOnLoadCallback(drawTable);
>>
>> function drawTable() {
>>
>> var data = new google.visualization.DataTable();
>>
>> data.addColumn('string', 'Created Date');
>>
>> data.addColumn('string', 'First Name');
>>
>> data.addColumn('string', 'Last Name');
>>
>> data.addColumn('string', 'Country');
>>
>> data.addColumn('string', 'Gender');
>>
>> data.addColumn('string', 'Birth Year-');
>>
>> data.addColumn('string', 'Month-');
>>
>> data.addColumn('string', 'Day');
>>
>> data.addColumn('string', 'Email Encrypted');
>>
>> data.addColumn('string', 'Password Encrypted');
>>
>> data.addRows([
>>
>> <?php
>>
>> $con = mysql_connect("blabla","blabla","passwordblabla");
>>
>> if (!$con)
>>
>> {
>>
>> die('Could not connect: ' . mysql_error());
>>
>> }
>>
>> mysql_select_db("robotfriend_org", $con);
>>
>> $result = mysql_query("SELECT *
>>
>> FROM Users
>>
>> Order by fname ASC");
>>
>> while($row = mysql_fetch_array($result))
>>
>> {
>>
>> echo "['" . $row['created_date'] . "',
>>
>> '" . $row['fname'] . "',
>>
>> '" . $row['lname'] . "',
>>
>> '" . $row['country'] . "',
>>
>> '" . $row['gender'] . "',
>>
>> '" . $row['year'] . "',
>>
>> '" . $row['month'] . "',
>>
>> '" . $row['day'] . "',
>>
>> '" . $row['email_encrypted'] . "',
>>
>> '" . $row['password'] . "'],";
>>
>> }
>>
>> mysql_close($con);
>>
>> echo "['', '', '', '', '', '', '', '', '', '']"; // MUST add NO "," in
>> the end (after password encrypted and]!!
>>
>> ?>
>>
>> ]);
>>
>> var table = new
>> google.visualization.Table(document.getElementById('table_div'));
>>
>> table.draw(data, {showRowNumber: true});
>>
>> }
>>
>> </script>
>>
>> </head>
>>
>> <body>
>>
>> <div id='table_div'></div>
>>
>> </body>
>>
>> </html>
>>
>>
>
>
> <https://lh6.googleusercontent.com/-mvwhINyDbJM/T9yYHgOr_3I/AAAAAAAAAAM/tNRNrhph_-U/s1600/Namnl%25C3%25B6s.jpg>
>
>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-visualization-api/-/-eBpkkBika4J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-visualization-api?hl=en.