1

这是我的表结构
在此处输入图像描述 在此处输入图像描述

  Here is my code: <br/>
  <?php 
     $result_journ = mysql_query("SELECT jour_id, journal FROM journals");                                                             
    $count_result = mysql_num_rows($result_journ);                                                


  while ($row_sd = mysql_fetch_array($result_journ)) {
   $data_sd = $row_sd['jour_id'];
   $namee= $row_sd['journal'];
  ?>

<script type="text/javascript">
    $(function () {
    $('#container_journal').highcharts({

        xAxis: {
            categories: [<?php
    $test_q = mysql_query("SELECT jour_id, year FROM journ_graph WHERE jour_id = '$data_sd'");
    while($row_q = mysql_fetch_array($test_q)){
        $year_q = $row_q['year']; 
        echo $year_q.',';
    }?>
       ]
        },
        yAxis: {
            title: {
                text: 'Citations'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },

        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'middle',
            borderWidth: 0
        },
        series: [{
            name: '<?php echo $namee; ?>',
            data: [<?php
    $sql= "SELECT `citations`, `jour_id` FROM `journ_graph` WHERE `jour_id` = '$data_sd'";
    $result=mysql_query($sql);
    $row = mysql_fetch_array($result);
    echo $cita = $row['citations'].',';
    ?>]
        }]
    });
});

</script>

   <?php
   }
   ?>

结果:
在此处输入图像描述 这是我得到的结果。

预期结果:
在此处输入图像描述

while 循环只得到一行。会有什么问题?请帮忙。while 循环只得到一行。会有什么问题?请帮忙。

更新结果
在此处输入图像描述

复选框选择
在此处输入图像描述

4

1 回答 1

1

您将在第一次的每次迭代中重新初始化 highcharts。试试下面的代码:

<?php
$result_journ = mysql_query("SELECT jour_id, journal FROM journals");
$count_result = mysql_num_rows($result_journ);
$categories = "";
$cita = array();
$count=0;
while ($row_sd = mysql_fetch_array($result_journ))
{
    $data_sd = $row_sd['jour_id'];
    $cita[$count]['name'] = $row_sd['journal'];

    $test_q = mysql_query("SELECT jour_id, year FROM journ_graph WHERE jour_id = '$data_sd'");

    while ($row_q = mysql_fetch_array($test_q))
    {
        $year_q = $row_q['year'];
        $categories .= $year_q . ',';
    }

    $sql = "SELECT `citations`, `jour_id` FROM `journ_graph` WHERE `jour_id` = '$data_sd'";
    $result = mysql_query($sql);

    // I have added this while block thinking that you might have more than one rows
    while ($row = mysql_fetch_array($result))
    {            
        $cita[$count]['data'][] = $row['citations'];
    }
    $count++;

}
?>

<script type="text/javascript">
    $(function () {
        $('#container_journal').highcharts({

            xAxis: {
                categories: [<?= $categories ?>]
            },
            yAxis: {
                title: {
                text: 'Citations'
            },
            plotLines: [{
                    value: 0,
                    width: 1,
                    color: '#808080'
                }]
        },

        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'middle',
            borderWidth: 0
        },
        series: <?= json_encode($cita, JSON_NUMERIC_CHECK) ?>
        });
    });
</script>
于 2013-10-08T01:50:25.637 回答