Advertisement
cdsatrian

generate query

Jan 10th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.89 KB | None | 0 0
  1. <pre>
  2. <?php
  3. // contoh data-nya
  4. $idnilai='201301';
  5. $nis='201003123';
  6. $lokal=3;
  7. $agm=8.7;
  8. $bin=7.4;
  9. $eng=8.5;
  10. $bas=7.9;
  11. $bar=8.2;
  12. $tgl_agm='04/01/2013';
  13. $tgl_bin='05/01/2013';
  14. $tgl_eng='06/01/2013';
  15. $tgl_bas='07/01/2013';
  16. $tgl_bar='08/01/2013';
  17.  
  18. //-- generate query-nya
  19. $mps=array('AGM','BIN','ENG','BAS','BAR');
  20. $qry=$qry2='';
  21. foreach($mps as $mp){
  22.   //-- model 1
  23.  $qry.="INSERT INTO tb_nilai_mid(mid_id,user_id,mid_lokal,mid_nilai,mid_mp,mid_tgl_ujian) "
  24.  ."VALUES('".$idnilai."$mp','$nis','$lokal','$bin','".${strtolower($mp)}."','".${"tgl_".strtolower($mp)}."');\n";
  25.   //-- model 2
  26.   $qry2.=(empty($qry2)?"INSERT INTO tb_nilai_mid(mid_id,user_id,mid_lokal,mid_nilai,mid_mp,mid_tgl_ujian) VALUES":",")
  27.   ."('".$idnilai."$mp','$nis','$lokal','$bin','".${strtolower($mp)}."','".${"tgl_".strtolower($mp)}."')\n";
  28. }
  29. //-- hasil generate query-nya
  30. echo $qry."\natau\n\n".$qry2.";";
  31. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement