Advertisement
cdsatrian

a

Nov 15th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. <?php
  2. include "koneksi.php";
  3. $query ="SELECT s.usia, s.berat_badan, s.tinggi_badan
  4. FROM status_gizi s, balita b
  5. WHERE s.balita_no_identitas=b.no_identitas
  6. AND b.jenis_kelamin='perempuan'
  7. AND s.balita_no_identitas=1";
  8. $hasil = mysql_query($query);
  9. $index=array('usia','berat_badan','tinggi_badan');
  10. $max=array('usia'=>0,'berat_badan'=>0,'tinggi_badan'=>0);
  11. $v=array();
  12. $i=0;
  13. $n=count($index);
  14. while ($data = mysql_fetch_array($hasil)){
  15. for($j=0;$j<$n;$j++){
  16. $bobot=mt_rand(1,1000)/10000;
  17. $v[$index[$j]]=$data[$index[$j]]*$bobot;
  18. echo $data[$index[$j]]." * ".$bobot." = ".$v[$index[$j]]."<br>\n";
  19. $max[$index[$j]]=($max[$index[$j]]<$v[$index[$j]]?$v[$index[$j]]:$max[$index[$j]]);
  20. }
  21. $i++;
  22. }
  23. for($i=0;$i<$n;$i++){
  24. echo "max ".ucwords(str_replace("_"," ",$index[$i]))." = ".$max[$index[$i]]."<br>\n";
  25. }
  26. ?>
  27. ===
  28. <?php
  29. include "koneksi.php";
  30. $query ="SELECT s.usia, s.berat_badan, s.tinggi_badan
  31. FROM status_gizi s, balita b
  32. WHERE s.balita_no_identitas=b.no_identitas
  33. AND b.jenis_kelamin='perempuan'
  34. AND s.balita_no_identitas=1";
  35. $hasil = mysql_query($query);
  36. $index=array('usia','berat_badan','tinggi_badan');
  37. $max=array('usia'=>0,'berat_badan'=>0,'tinggi_badan'=>0);
  38. $v=array();
  39. $total=array();
  40. $i=0;
  41. $n=count($index);
  42. while ($data = mysql_fetch_array($hasil)){
  43. for($j=0;$j<$n;$j++){
  44. $bobot=mt_rand(1,1000)/10000;
  45. $v[$index[$j]]=$data[$index[$j]]*$bobot;
  46. $total[$index[$j]]+=$data[$index[$j]];
  47. $max[$index[$j]]=($max[$index[$j]]<$v[$index[$j]]?$v[$index[$j]]:$max[$index[$j]]);
  48. }
  49. $i++;
  50. }
  51. for($i=0;$i<$n;$i++){
  52. echo "max ".ucwords(str_replace("_"," ",$index[$i]))." = ".($max[$index[$i]]/$total[$index[$i]])."<br>\n";
  53. }
  54. ?>
  55. ===
  56. <?php
  57. include "koneksi.php";
  58. $query ="SELECT s.usia, s.berat_badan, s.tinggi_badan
  59. FROM status_gizi s, balita b
  60. WHERE s.balita_no_identitas=b.no_identitas
  61. AND b.jenis_kelamin='perempuan'
  62. AND s.balita_no_identitas=1";
  63. $hasil = mysql_query($query);
  64. $value_title=array('usia','berat_badan','tinggi_badan');
  65. $value=array();
  66. $total=array(0,0,0);
  67. $i=0;
  68. $n=count($value_title);
  69. while ($data = mysql_fetch_array($hasil)){
  70. $value[$i]=array();
  71. for($j=0;$j<$n;$j++){
  72. $value[$i][$j]=$data[$j];
  73. $total[$j]+=$data[$j];
  74. }
  75. $i++;
  76. }
  77. //------------
  78. $jumlah_data=$i-1;
  79. $bobot=array();
  80. $value_bobot=array();
  81. $max=array(0,0,0);
  82. for($i=0;$i<$jumlah_data;$i++){
  83. $bobot[$i]=array();
  84. $value_bobot[$i]=array();
  85. for($j=0;$j<$n;$j++){
  86. $bobot[$i][$j]=(mt_rand(1,1000)/10000)/$total[$j];
  87. $value_bobot[$i][$j]=$value[$i][$j]*$bobot[$i][$j];
  88. $max[$j]=$max[$j]<$value_bobot[$i][$j]?$value_bobot[$i][$j]:$max[$j];
  89. echo $value[$i][$j]." * ".$bobot[$i][$j]." = ".$value_bobot[$j]."<br>\n";
  90. }
  91. }
  92. //------------
  93. $value_title=array('usia','berat_badan','tinggi_badan');
  94. for($i=0;$i<$n;$i++){
  95. echo "max ".ucwords(str_replace("_"," ",$value_title[$i]))
  96. ." = ".$max[$i]."<br>\n";
  97. }
  98. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement