2015-01-09 63 views
0

我從數據庫中獲取了用戶,並且他們都有評論得分。 我使用while語句顯示每個用戶和評論分數(使用highchart)。無法顯示每個元素的高圖

問題是我得到的只有一個圖表,而不是每個單個用戶獲取一個圖表。

下面是代碼

PHP:

if (isset($_COOKIE['rev_idx'])) { 
    $review_id=preg_replace('#[^0-9]#','',$_COOKIE['rev_idx']); 
    if ($review_id==$get_rev) { 
     $sql1="SELECT * FROM `user`.`review` WHERE reviewer_id='$review_id'"; 
     $query1=mysqli_query($connect_dude,$sql1); 
     if (mysqli_num_rows($query1)>0) { 
      $show_review=""; 

      while($row1=mysqli_fetch_assoc($query1)){ 
       $rid=$row1['rid']; 
       $reviewer_id=$row1['reviewer_id']; 
       $reviewee_id=$row1['reviewee_id']; 
       $review_tit=$row1['review_tit']; 
       $review=$row1['review']; 
       $image=$row1['image']; 
       $point=$row1['points']; 
       $rev_date=$row1['rev_date']; 

       $sql2="SELECT * FROM `user`.`user_det` WHERE id='$reviewee_id'"; 
       $query2=mysqli_query($connect_dude,$sql2); 
       if(mysqli_num_rows($query2)>0){ 
        $row2=mysqli_fetch_assoc($query2); 
        $image=$row2['img']; 
        $busi_title=$row2['busi_title']; 

        $show_review.="<br><div id='indi_rev'><div style='width:600px;border-bottom:1px solid black;'></div><div id='rev_dat'>".$rev_date."</div> 
          <div style='width:600px;border-bottom:1px solid black;'></div> 
          <div style='float:left;'><a href='../".$reviewee_id."/index.php'><img src='../account/".$reviewee_id."/".$image."' width='130' height='150'></a><br><a href='../".$reviewee_id."/index.php'><b>".$busi_title."</b></a></div> 

          <div><br><b>".$review_tit."</b><br>".$review."</div><div id='Scores' style='min-width: 100px; height: 80px;max-width: 500px;'></div></div>"; 

       }         
      } 
     } else { 
      $show_review="<b>You have not written any review yet.</b><br>Share your thought to others by writing review."; 
     } 
    } else { 
     header("location:reviewer.php?usr=".$review_id.""); 
    } 
} 

的Javascript:

<script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script> 
<script src="http://code.highcharts.com/highcharts.js" type="text/javascript"></script> 

<script> 
    $(document).ready(function() { 
     var x="<?php echo $point;?>"; 
     var chart = new Highcharts.Chart({ 
      chart: { 
       type: 'bar', 
       renderTo: 'Scores', 
       marginRight: 50, 
       events: { 
        //load: loadRed 
       } 
      }, 
      title: { 
       text: '', 
       style: { 
        color: 'black', 
        fontWeight: '700', 
        fontFamily: 'Arial', 
        fontSize: 20 
       } 
      }, 
      xAxis: { 
       categories: ['Review Score'], 
       title: { 
        text: null 
       }, 
       gridLineWidth: 0, 
       minorGridLineWidth: 0, 
       labels: { 
        style: { 
         color: 'black', 
         fontWeight: '700', 
         fontFamily: 'Arial', 
         fontSize: 11, 
         width: 90 
        } 
       } 
      }, 
      yAxis: { 
       min: 0, 
       max: 100, 
       gridLineWidth: 0, 
       minorGridLineWidth: 0, 
       labels: { 
        enabled: false 
       }, 
       title: { 
        text: null 
       } 
      }, 

      tooltip: { 
       valueSuffix: ' /100' 
      }, 

      plotOptions: { 
       series: { 
        stacking: 'percent' 
       }, 
       bar: { 
        grouping: false, 
        dataLabels: { 
         enabled: false 
        } 
       } 
      }, 
      legend: { 
       enabled: false, 
       align: 'right', 
       x: -40, 
       y: 100, 
       floating: false, 
       borderWidth: 0, 
       backgroundColor: '#FFFFFF', 
       shadow: false 
      }, 
      credits: { 
       enabled: false 
      }, 
      series: [ 
       { 
        name: 'null', 
        data: [x], 
        borderWidth: 0, 
        color: "rgba(0,0,0,0)" 
       }, { 
        name: 'Score', 
        data: [x], 
        borderWidth: 0, 
        stack: 1, 
        animation: false, 
        color: "gray" 
       }, { 
        name: 'Score', 
        data: [x], 
        color: "green", 
        borderWidth: 0, 
        borderRadius: 5 
       } 
      ] 
     }); 
    }); 
</script> 

您的幫助將不勝感激

回答

0

你應該做highcahrt的許多實例對於很多用戶通過添加不同的ID並循環你的JavaScript代碼。

更改

<div id='Scores' .... 

<div id='Scores_".$reviewee_id."' .... 

,並減少你的

< SCRIPT>

塊和後貼

$show_review.="<br><div ...... 

,改變

renderTo: 'Scores', 

renderTo: 'Scores_<?php echo $reviewee_id>', 
0

的問題是,你的x變量是字符串,而應該是一個數組。所以考慮用php JSON(json_encode())進行打印,然後用函數$ .getJSON()來嘲諷javascript。