What about SQL? can you please help me to get data from SQL and create 
Chart please?

On Monday, June 18, 2012 at 11:28:00 AM UTC-5, asgallant wrote:
>
> 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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-visualization-api/b19ea945-c449-42a5-beaf-d776faaa4306%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to