如何使用 PHP 从 MySQL 数据库填充 google 可视化数据 table?

How to populate google visualization data table from MySQL database with PHP?

```
<?php
// open database connection
$connection = mysqli_connect('localhost', '', '');
// sql query
$result = mysql_query($connection, "SELECET name, author, publisher, yearOfPublish, ISBN 
FROM books");
if(!$connection) {
    die("Connection failer: " . mysqli_connect_error());
}
echo "Connected Succes";
?>

// html code 
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Main Page</title>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['table']});
google.charts.setOnLoadCallback(drawTable);
// draw table function
function drawTable() {
var data = new google.visualization.DataTable();
// add columns
data.addColumn('string', 'Name');
data.addColumn('string', 'Author');
data.addColumn('string', 'Publisher');
data.addColumn('number', 'Year Of Publish');
data.addColumn('number', 'ISBN');
// add rows
data.addRows([
// retrieve data from database
]);
...
```

我有一个保存书籍信息的数据库,我正在尝试检索这些书籍信息并将它们放入 google 数据 table。我成功地打开了与数据库的连接。但是,我不知道如何执行查询并从数据库中获取数据。

function drawTable() {
var data = google.visualization.arrayToDataTable([
['Title', 'Author', 'Publisher', 'Year Of Publish', 'ISBN'],
        <?php while ($row = mysqli_fetch_array($result)) {?>
        ['<?php echo $row['name']?>' , '<?php echo $row['author']?>', '<?php echo $row['publisher']?>', '<?php echo $row['yearOfPublish']?>', '<?php echo $row['ISBN']?>'],
        <?php } ?>
    ]);
    var table = new google.visualization.Table(document.getElementById('table_div'));

    table.draw(data, {showRowNumber: true, width: '50%', height: '50%'});
}

我找到了解决方案