@Emily:
I copied your exact code, changed the database info to my credentials,
changed the SQL query to the fetch the data I needed, and I get a blank
page when opening. There is no graph shown. Is there something I'm missing?
Thanks,
Andrew
On Thursday, August 18, 2016 at 8:40:23 AM UTC-4, Emile wrote:
>
> <?php
>>
>> $hostname = "localhost";
>> $username = "xxxxxx";
>> $password = "xxxxxx";
>> $database = "ecb";
>> $tabel = "eurorates";
>>
>> // Create connection
>> $conn = mysqli_connect($hostname, $username, $password, $database);
>> // Check connection
>> if (!$conn) {
>> die("Connection failed: " . mysqli_connect_error());
>> }
>>
>> //set array variable
>> $results = array();
>>
>> //talk to the db
>> $sql="SELECT * FROM eurorates WHERE currency = 'GBP' ORDER BY date DESC
>> limit 100";
>> $result = mysqli_query($conn, $sql);
>>
>> //count the rows and fields
>> $totalRows = mysqli_num_rows($result);
>> $totalFields = mysqli_num_fields($result);
>>
>> //start the loop
>> for ( $i = 0; $i < $totalRows; ++$i ) {
>>
>> //make it 2 dim in case you change your order
>> $results[$i] = mysqli_fetch_array($result);
>> }
>>
>> ?>
>>
>> <html>
>> <head>
>> <script type="text/javascript" src="http://www.google.com/jsapi
>> "></script>
>> <script type="text/javascript">
>> google.load( 'visualization', '1', { 'packages': [ 'corechart' ] }
>> );
>> google.setOnLoadCallback( drawChart );
>>
>> function drawChart() {
>> var data = new google.visualization.DataTable();
>>
>> data.addColumn( 'string', 'Datum' );
>> data.addColumn( 'number', 'Rate' );
>>
>> data.addRows(100);
>>
>> <?php
>>
>> $i = 0;
>> $numofloops = 100;
>>
>> while($i < $numofloops){
>>
>> echo "data.setValue($i, 0, '" . $results[$i]["date"] . "');";
>> echo "data.setValue($i, 1, " . $results[$i]["rate"] . ");";
>>
>> $i++;
>> }
>> ?>
>>
>> var options = {title: 'Echangerate EUR - GBP',
>> vAxis: {title: "Rate"},
>> hAxis: {title: "Date"},
>> colors: ['red','#004411']
>> };
>>
>> var chart = new
>> google.visualization.LineChart(document.getElementById('chart_div'));
>> chart.draw( data, options);
>> }
>> </script>
>> </head>
>> <body>
>> <div id="chart_div" style="width: 1500px; height: 800px;"></div>
>> </body>
>> </html>
>>
>>
--
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/af0126ef-d873-4380-b4d9-487ab6fd72a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.