Php 使用highcharts和MySQL

Php 使用highcharts和MySQL,php,mysql,highcharts,Php,Mysql,Highcharts,我想用海图制作图形,我试着把它和我的数据库连接起来,但它不起作用。。我不知道会出什么问题。。以下是我的代码和数据库中的表格: <!DOCTYPE HTML> <?php include "conectar.php"; ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

我想用海图制作图形,我试着把它和我的数据库连接起来,但它不起作用。。我不知道会出什么问题。。以下是我的代码和数据库中的表格:

    <!DOCTYPE HTML>
<?php 
    include "conectar.php";

?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Highcharts Example</title>

        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
        <style type="text/css">
${demo.css}
        </style>
        <script type="text/javascript">
$(function () {
    $('#container').highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: 1,//null,
            plotShadow: false
        },
        title: {
            text: 'Browser market shares at a specific website, 2014'
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                    style: {
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                    }
                }
            }
        },
        series: [{
            type: 'pie',
            name: 'Consumidores',
            data: [
            <?php
                $sql = "select * from consumidores";
                        $result = mysql_query($con,$sql);
                        while($row=mysql_fetch_array($result, MYSQL_ASSOC)){ ?>

                ['<?php echo $row["Nombre"] ?>',  <?php echo $row["Edad"] ?>],
                    <?php } ?>
            ]
        }]
    });
});



        </script>
    </head>
    <body>
<script src="../../js/highcharts.js"></script>
<script src="../../js/modules/exporting.js"></script>

<div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>

    </body>
</html>
浏览器源代码视图的输出:

<!DOCTYPE HTML>
<?php 
    include "conectar.php";

?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Highcharts Example</title>

        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
        <style type="text/css">
${demo.css}
        </style>
        <script type="text/javascript">
$(function () {
    $('#container').highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: 1,//null,
            plotShadow: false
        },
        title: {
            text: 'Browser market shares at a specific website, 2014'
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                    style: {
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                    }
                }
            }
        },
        series: [{
            type: 'pie',
            name: 'Consumidores',
            data: [
            <?php
                $sql = "select * from consumidores";
                        $result = mysql_query($con,$sql);
                        while($row=mysql_fetch_array($result, MYSQL_ASSOC)){ ?>

                ['<?php echo $row["Nombre"] ?>',  <?php echo $row["Edad"] ?>],
                    <?php } ?>
            ]
        }]
    });
});



        </script>
    </head>
    <body>
<script src="../../js/highcharts.js"></script>
<script src="../../js/modules/exporting.js"></script>

<div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>

    </body>
</html>

不工作意味着什么?另外,如果这是新代码,请不要使用不推荐使用的mysql_uu函数。取而代之的是,使用mysqli_uu或PDO。你在控制台中有任何JavaScript错误吗?我已经尝试过mysqli_uu。。。我的意思是,当我试图用来自database@halfer不,我没有收到任何错误,只是一个空白页面您的脚本没有解析为php。。。由于html输出中有php标记。。。
CREATE TABLE `consumidores` (
    `ID_consumidor` INT(10) NOT NULL AUTO_INCREMENT,
    `Nombre` VARCHAR(100) NULL DEFAULT NULL COLLATE 'latin1_spanish_ci',
    `Edad` INT(3) NULL DEFAULT NULL,
    `Sexo` VARCHAR(50) NULL DEFAULT NULL COLLATE 'latin1_spanish_ci',
    `SalarioM` VARCHAR(50) NULL DEFAULT NULL COLLATE 'latin1_spanish_ci',
    `PreferenciaCompras` VARCHAR(50) NULL DEFAULT NULL COLLATE 'latin1_spanish_ci',
    `Direccion` VARCHAR(100) NULL DEFAULT NULL COLLATE 'latin1_spanish_ci',
    `Correo` VARCHAR(100) NULL DEFAULT NULL COLLATE 'latin1_spanish_ci',
    `Ciudad` VARCHAR(100) NULL DEFAULT NULL COLLATE 'latin1_spanish_ci',
    `EstadoCivil` VARCHAR(100) NULL DEFAULT NULL COLLATE 'latin1_spanish_ci',
    `TarjetaCredito` VARCHAR(20) NULL DEFAULT NULL COLLATE 'latin1_spanish_ci',
    PRIMARY KEY (`ID_consumidor`)
)
COLLATE='latin1_spanish_ci'
ENGINE=MyISAM
AUTO_INCREMENT=41;
<!DOCTYPE HTML>
<?php 
    include "conectar.php";

?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Highcharts Example</title>

        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
        <style type="text/css">
${demo.css}
        </style>
        <script type="text/javascript">
$(function () {
    $('#container').highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: 1,//null,
            plotShadow: false
        },
        title: {
            text: 'Browser market shares at a specific website, 2014'
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                    style: {
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                    }
                }
            }
        },
        series: [{
            type: 'pie',
            name: 'Consumidores',
            data: [
            <?php
                $sql = "select * from consumidores";
                        $result = mysql_query($con,$sql);
                        while($row=mysql_fetch_array($result, MYSQL_ASSOC)){ ?>

                ['<?php echo $row["Nombre"] ?>',  <?php echo $row["Edad"] ?>],
                    <?php } ?>
            ]
        }]
    });
});



        </script>
    </head>
    <body>
<script src="../../js/highcharts.js"></script>
<script src="../../js/modules/exporting.js"></script>

<div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>

    </body>
</html>