Consulta MSSQL com ARRAY

PHP

23/03/2018

Preciso criar um array para montar um gráfico com os dados obtidos de uma consulta MSSQL conforme segue abaixo, mas não consigo o valor de quantidade, desculpem qualquer erro mas editei o código para ficar mais didático.

<html>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<?php
require ''''''''conexao.php'''''''';

$QUANTIDADE = array('''''''''''''''',''''''''1'''''''',''''''''2'''''''');
for($x=1;$x<=3;$x=$x+1){
$quantidade[$x]=0;
}

$query = "SELECT empresa.NOMEFANTASIA AS [COLIGADA],
SUM(1) AS [QUANTIDADE]
FROM
cadastros

$statement = $db->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
?>


<!DOCTYPE html> <html>
<head>
<meta charset="utf-8">
<title>ALUNOS 2018</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/custom.css">
</head>
<body>

<!-- Logotipo -->
<div class="header-top">
<div class="container">
<div class="head-main">
<center><img src="../logo.png" width="280 " height="100" alt="Logo" />
</div>

<!DOCTYPE html> <div class=''''''''container''''''''>
<fieldset>
<!-- Cabeçalho da Listagem -->
<center> <legend> <h1>CONSULTA </h1> </legend>

</form><br>

<!-- Tabela -->
<table class="table table-striped">
<tr class=''''''''active''''''''>
<td>COLIGADA</td>
<td>QUANTIDADE</td>

</tr>

<?php foreach($result as $linha) {?>
<tr>
<td><?php echo utf8_encode($linha[''''''''COLIGADA'''''''']); ?></td>
<td><?php echo utf8_encode($linha[''''''''QUANTIDADE'''''''']); ?></td>
</tr> <?php }




<script type="text/javascript" src="js/custom.js"></script>


<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">

// Load the Visualization API and the corechart package.
google.charts.load(''''''''current'''''''', {''''''''packages'''''''':[''''''''corechart'''''''']});

// Set a callback to run when the Google Visualization API is loaded.
google.charts.setOnLoadCallback(drawChart);

// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {

// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn(''''''''string'''''''', ''''''''Topping'''''''');
data.addColumn(''''''''number'''''''', ''''''''Slices'''''''');
data.addRows([
[''''''''teste1'''''''', <?php echo utf8_encode($QUANTIDADE[''''''''0'''''''']); ?>],
[''''''''teste1'''''''', <?php echo utf8_encode($QUANTIDADE[''''''''1'''''''']); ?>],
[''''''''teste1'''''''', <?php echo utf8_encode($QUANTIDADE[''''''''2'''''''']); ?>],
[''''''''teste'''''''', 86],
]);

// Set chart options
var options = {''''''''title'''''''':''''''''Número de alunos 2018'''''''',
''''''''width'''''''':900,
''''''''height'''''''':300};


// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.PieChart(document.getElementById(''''''''chart_div''''''''));
chart.draw(data, options);
}


</script>
</head>

<body>
<!--Div that will hold the pie chart-->
<div id="chart_div"></div>
</body>
Wiliam

Wiliam

Curtidas 0
POSTAR