justhrun

highcharts_data.php

Sep 16th, 2014
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. <?php
  2. $con = mysql_connect("localhost","root","");
  3. mysql_select_db("graph2", $con);
  4.  
  5. $rkecam = mysql_query("select nama from kecamatan order by id_kec");
  6. while(list($nama) = mysql_fetch_row($rkecam)) { $category['kecamatan'][] = $nama; }
  7. mysql_free_result($rkecam);
  8.  
  9. $rcalon = mysql_query("select id_calon, nama_calon from calon order by id_calon");
  10. while(list($id,$nama) = mysql_fetch_row($rcalon)) {
  11.         $arrnama['nama'][] = $nama;
  12.         $arrsuara = array();
  13.         $rhasil = mysql_query("select suara from hasil where id_calon='$id' order by id_kec");
  14.         while(list($suara) = mysql_fetch_row($rhasil)) { $arrsuara[] = $suara; }
  15.         mysql_free_result($rhasil);
  16.         $suara = join($arrsuara, ',');
  17.         $data['hasil'][] = array("name"=>$nama,"data"=>$arrsuara);
  18. }
  19. mysql_free_result($rcalon);
  20. mysql_close($con);
  21.  
  22. $result[] = $category;          // json[0]
  23. $result[] = $data;              // json[1]
  24. print json_encode($result, JSON_NUMERIC_CHECK);
  25. ?>
Advertisement
Add Comment
Please, Sign In to add comment