2

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

在此处输入图像描述

我正在使用高图表

这是我的代码:

    $(function () {
      $('#container_journal').highcharts({

        xAxis: {
            categories: [
                 '1995', '1996', '1997', '1988'
        ]
        },
        yAxis: {
            title: {
                text: 'Citations'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        tooltip: {
            valueSuffix: ''
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'middle',
            borderWidth: 0
        },
        series: [{
            name: 'A + U-Architecture and Urbanism',
            data: [<?php 
            $test_q = mysql_query("SELECT jour_id, journal, citations, year FROM journ_graph WHERE jour_id = '1'");
    while($row_q = mysql_fetch_array($test_q)){
        $year_q = $row_q['year'];
        $citations_q = $row_q['citations'];
        echo $citations_q.',';
    }
        ?>]
        },{
            name: 'AACE International. Transactions of the Annual Meeting',
            data: [
                   <?php 
            $test_q = mysql_query("SELECT jour_id, journal, citations, year FROM journ_graph  WHERE jour_id = '2'");
                         while($row_q =  mysql_fetch_array($test_q)){
                            $year_q = $row_q['year'];
                            $citations_q =  $row_q['citations'];
                            echo $citations_q.',';
                         }
       ?>]
         },{
            name: 'AACL Bioflux',
            data: [
                   <?php 
              $test_q = mysql_query("SELECT jour_id, journal, citations, year FROM journ_graph WHERE jour_id = '3'");
    while($row_q = mysql_fetch_array($test_q)){
    $year_q = $row_q['year'];
    $citations_q = $row_q['citations'];
    echo $citations_q.',';
    }
         ?>]
        }
      ?>]
      ]
    });
   });

我在这里手动输入ID。在 where 子句(参考代码)中,图表正在显示。往下看:在此处输入图像描述 SELECT jour_id, journal, citations, year FROM journ_graph WHERE jour_id = '3' 在上面的语句中,我手动输入了 id,但我需要它来自第一个表 jour_id。

我也试过了,但它不起作用。

   series: [
    <?php 
    $query_jour = mysql_query("SELECT jour_id, journal, citations, year FROM journ_graph");
                                                     $query_journ_count = mysql_num_rows($query_jour);
                                         while($row_journ = mysql_fetch_array($query_jour)){
                                         $jour_id = $row_journ['jour_id'];

  ?>
    {
            data: [<?php 
          $test_q = mysql_query("SELECT jour_id, journal, citations, year FROM journ_graph WHERE jour_id = '$jour_id'");
    while($row_q = mysql_fetch_array($test_q)){
        $year_q = $row_q['year'];
        $citations_q = $row_q['citations'];
        echo $citations_q.',';
    }
    ?>]
       }
  <?php
  }?>

我使用了两个 while 循环,但即使它不起作用。请告诉我哪里出错了。请帮忙。

4

1 回答 1

0

我建议您对数据库运行一个查询,准备包含三个系列的数组,然后在 PHP 中使用 json_encode() 并在 javascript 中通过 AJAX 获取数据。会更清楚。

于 2013-10-07T09:55:22.017 回答