gini gan gmna caranya menyimpan data setelah dipilih pada combobox, jadi gini file combobox
  1.  
  2. <form action="" method="post">
  3. <select name="id_peserta">
  4. <option>-Pilih Hasil Undian-</option>
  5. <?php
  6. $host = "localhost";
  7. $user = "root";
  8. $pass = "";
  9. $db = "db_arisan";
  10. $connect = mysql_connect($host, $user, $pass);
  11. $sukses = mysql_select_db($db, $connect);
  12.  
  13. $tanggal = @$_POST['tanggal'];
  14. $nama_peserta = @$_POST['nama_peserta'];
  15. $alamat = @$_POST['alamat'];
  16. $no_hp = @$_POST['no_hp'];
  17. $jenis_kelamin = @$_POST['jenis_kelamin'];
  18.  
  19. $sql = mysql_query("SELECT * FROM tbl_peserta ORDER BY id_peserta ASC");
  20. if(mysql_num_rows($sql) != 0){
  21. while($data = mysql_fetch_assoc($sql)){
  22. echo '<option>'.$data['id_peserta'].'</option>';
  23. }
  24. }
  25. ?>
  26. <input type="submit" name="submit" value="OK" />
  27. </select>
  28. </form>
trus ini code menyimpan pada tabel setelah combobox dipilih dan tombol ok ditekan
  1. <?php
  2. $host = "localhost";
  3. $user = "root";
  4. $pass = "";
  5. $db = "db_arisan";
  6. $connect = mysql_connect($host, $user, $pass);
  7. $sukses = mysql_select_db($db, $connect);
  8.  
  9. $id_peserta = @$_POST['id_peserta'];
  10. $tanggal = @$_POST['tanggal'];
  11. $nama_peserta = @$_POST['nama_peserta'];
  12. $alamat = @$_POST['alamat'];
  13. $no_hp = @$_POST['no_hp'];
  14. $jenis_kelamin = @$_POST['jenis_kelamin'];
  15.  
  16. $pemenang =@$_POST['submit'];
  17.  
  18. if($pemenang) {
  19. mysql_query ("insert into tbl_record (id_peserta,tanggal,nama_peserta,alamat,no_hp,jenis_kelamin) values ('$id_peserta', '$tanggal', '$nama_peserta', '$alamat', '$no_hp', '$jenis_kelamin')") or die (mysql_error());
  20. {
  21. ?>
  22. <script type="text/javascript">
  23. alert("PEMENANG ARISAN BULAN INI ADALAH...");
  24. window.location.href = "work03.php?page=record";
  25. </script>
  26. <?php
  27. }
  28. }
  29. ?>
dan ini tabel tempat nantinya data disimpan
  1. <table width="100%" border="1px" style="border-collapse:collapse;">
  2. <tr style="background-color:#33CCB7">
  3. <th style="text-align: center; color: #000000;">ID PESERTA</th>
  4. <th style="text-align: center; color: #000000;">TANGGAL DAFTAR</th>
  5. <th style="text-align: center; color: #000000;">NAMA</th>
  6. <th style="text-align: center; color: #000000;">ALAMAT</th>
  7. <th style="text-align: center; color: #000000;">TELEPON</th>
  8. <th style="text-align: center; color: #000000;">JENIS KELAMIN</th>
  9. <th style="text-align: center; color: #000000;">OPSI</th>
  10. </tr>
  11. <?php
  12. $host = "localhost";
  13. $user = "root";
  14. $pass = "";
  15. $db = "db_arisan";
  16. $connect = mysql_connect($host, $user, $pass);
  17. $sukses = mysql_select_db($db, $connect);
  18. $sql = mysql_query("select * from tbl_record") or die (mysql_error());
  19. while ($data = mysql_fetch_array($sql)) {
  20. ?>
  21. <tr>
  22. <td id="id_peserta" style="text-align: center"><?php echo $data['id_peserta']; ?></td>
  23. <td id="tanggal" style="text-align: left"><?php echo $data['tanggal']; ?></td>
  24. <td id= "nama_peserta" style="text-align: left"><?php echo $data['nama_peserta']; ?></td>
  25. <td id="alamat" style="text-align: left"><?php echo $data['alamat']; ?></td>
  26. <td id="no_hp" style="text-align: left"><?php echo $data['no_hp']; ?></td>
  27. <td id="jenis_kelamin" style="text-align: left"><?php echo $data['jenis_kelamin']; ?></td>
  28. <td>
gimana caranya ketika memilih salah satu combobox kemudian di tekan 'ok' maka value akan tersimpan pada tabel yg diambil dari nilai combobox
mohon bantuan secepatnya :(
Please login to answer!
Mohon bantuannya, saya bingung melakukan get textboxt sebagai nama tabel database yang ingin digunakan.
  1. <?php //proses-ajax.php
  2. include 'koneksi.php';
  3. $nim = $_GET['nim'];
  4. $nama = "mahasiswa";//mau dibikin $nama = $_GET['namatabel'];
  5. $query = mysqli_query($koneksi, "select * from $nama where nim='$nim'");
  6. $mahasiswa = mysqli_fetch_array($query);
  7. $data = array(
  8. 'jurusan' => $mahasiswa['jurusan'],
  9. 'alamat' => $mahasiswa['alamat'],);
  10. echo json_encode($data);
  11. ?>
  12.  

ini form ajaxnya
  1. <!DOCTYPE html> <!--form-ajax.php-->
  2. <html>
  3. <head>
  4. <title>Ajax Jquery - Belajarphp.net</title>
  5. </head>
  6. <body>
  7. <form action="">
  8. <table>
  9. <tr><td>NIM</td><td><input type="text" onkeyup="isi_otomatis()" id="nim"></td></tr>
  10. <tr><td>NAMA TABEL</td><td><input type="text" id="namatabel"></td></tr>
  11. <tr><td>JURUSAN</td><td><input type="text" id="jurusan"></td></tr>
  12. <tr><td>ALAMAT</td><td><input type="text" id="alamat"></td></tr>
  13. </table>
  14. </form>
  15. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  16. <script type="text/javascript">
  17. function isi_otomatis(){
  18. var nimi = $("#nim").val();
  19. $.ajax({
  20. url: 'proses-ajax.php',
  21. data:"nim="+nimi,
  22. }).success(function (data) {
  23. var json = data,
  24. obj = JSON.parse(json);
  25. $('#jurusan').val(obj.jurusan);
  26. $('#alamat').val(obj.alamat);
  27. });
  28. }
  29. </script>
  30. </body>
  31. </html>

Terima kasih sebelumnnya
Please login to answer!
  1. <?php
  2. //include file koneksi ke database
  3. include('config/koneksi.php');
  4. ?>
  5.  
  6.  
  7. <?php
  8.  
  9. $query = mysqli_query($koneksi, "SELECT * FROM soal INNER JOIN kategori USING (kid) WHERE kid='3' AND id_ujian='ujian' order by rand()") or die (mysqli_error());
  10. $jumlah=mysqli_num_rows($query); // jumlah baris soal yang dipilih
  11.  
  12. //cek, apakah hasil query mendapatkan hasil atau tidak
  13. //jika data kosong
  14. if(mysqli_num_rows($query) == 0){
  15. echo '<tr><td colspan="6">Tidak ada data!</td></tr>';
  16. } else{ // jika data ada
  17. $no = 1;
  18. while($data = mysqli_fetch_assoc($query)){
  19. ?>
  20.  
  21. <tr>
  22. <td><?php echo $no++; ?></td>
  23. <td>
  24. <?php
  25. echo $data['soal'];
  26. $sid=$data['sid'];
  27. $id_ujian=$data['id_ujian'];
  28. ?>
  29.  
  30. <input type="hidden" name="id[]" value=<?php echo $sid; ?>>
  31. <input type="hidden" name="id_ujian" value=<?php echo $id_ujian; ?>>
  32. <input type="hidden" name="jumlah" value=<?php echo $jumlah;?>>
  33. <input type="hidden" name="kid" value=<?php echo $data['kid'];?>>
  34. </td>
  35. </tr>
  36.  
  37. <tr>
  38. <td></td>
  39. <td>
  40. <?php
  41. $data2=mysqli_query($koneksi, "SELECT * FROM jawaban WHERE sid='$sid' ORDER BY rand()");
  42. while($jawaban=mysqli_fetch_array($data2))
  43. { ?>
  44.  
  45. <div>
  46. <?php $id=$jawaban["sid"]; ?>
  47. <input type="radio" id="pilihan1" name="pilihan1[<?php echo $id; ?>]" value="<?php echo $jawaban['benar'];?>" >
  48. <?php echo $jawaban['jawaban']; ?><br>
  49. </div>
  50.  
  51. <?php
  52. } //akhir perulangan jawaban
  53. ?>
  54. </td>
  55. </tr>
  56.  
  57. <?php
  58. } //akhir perulangan soal
  59. } //tutup else
  60. ?>
  61.  
  62. <?php
  63.  
  64. $query = mysqli_query($koneksi, "SELECT * FROM soal INNER JOIN kategori USING (kid) WHERE kid='2' AND id_ujian='ujian' order by rand()") or die (mysqli_error());
  65. $jumlah=mysqli_num_rows($query); // jumlah baris soal yang dipilih
  66.  
  67. //cek, apakah hasil query mendapatkan hasil atau tidak
  68. //jika data kosong
  69. if(mysqli_num_rows($query) == 0){
  70. echo '<tr><td colspan="6">Tidak ada data!</td></tr>';
  71. } else{ // jika data ada
  72. $no = 1;
  73. while($data = mysqli_fetch_assoc($query)){
  74. ?>
  75.  
  76. <tr>
  77. <td><?php echo $no++; ?></td>
  78. <td>
  79. <?php
  80. echo $data['soal'];
  81. $sid=$data['sid'];
  82. $id_ujian=$data['id_ujian'];
  83. ?>
  84.  
  85. <input type="hidden" name="id[]" value=<?php echo $sid; ?>>
  86. <input type="hidden" name="id_ujian" value=<?php echo $id_ujian; ?>>
  87. <input type="hidden" name="jumlah" value=<?php echo $jumlah;?>>
  88. <input type="hidden" name="kid" value=<?php echo $data['kid'];?>>
  89. </td>
  90. </tr>
  91.  
  92. <tr>
  93. <td></td>
  94. <td>
  95. <?php
  96. $data2=mysqli_query($koneksi, "SELECT * FROM jawaban WHERE sid='$sid' ORDER BY rand()");
  97. while($jawaban=mysqli_fetch_array($data2))
  98. { ?>
  99.  
  100. <div>
  101. <?php $id=$jawaban["sid"]; ?>
  102. <input type="radio" id="pilihan2" name="pilihan2[<?php echo $id; ?>]" value="<?php echo $jawaban['benar'];?>" >
  103. <?php echo $jawaban['jawaban']; ?><br>
  104. </div>
  105.  
  106. <?php
  107. } //akhir perulangan jawaban
  108. ?>
  109. </td>
  110. </tr>
  111.  
  112. <?php
  113. } //akhir perulangan soal
  114. } //tutup else
  115. ?>
  116.  
  117. <?php
  118.  
  119. $query = mysqli_query($koneksi, "SELECT * FROM soal INNER JOIN kategori USING (kid) WHERE kid='1' AND id_ujian='ujian' order by rand()") or die (mysqli_error());
  120. $jumlah=mysqli_num_rows($query); // jumlah baris soal yang dipilih
  121.  
  122. //cek, apakah hasil query mendapatkan hasil atau tidak
  123. //jika data kosong
  124. if(mysqli_num_rows($query) == 0){
  125. echo '<tr><td colspan="6">Tidak ada data!</td></tr>';
  126. } else{ // jika data ada
  127. $no = 1;
  128. while($data = mysqli_fetch_assoc($query)){
  129. ?>
  130.  
  131. <tr>
  132. <td><?php echo $no++; ?></td>
  133. <td>
  134. <?php
  135. echo $data['soal'];
  136. $sid=$data['sid'];
  137. $id_ujian=$data['id_ujian'];
  138. ?>
  139.  
  140. <input type="hidden" name="id[]" value=<?php echo $sid; ?>>
  141. <input type="hidden" name="id_ujian" value=<?php echo $id_ujian; ?>>
  142. <input type="hidden" name="jumlah" value=<?php echo $jumlah;?>>
  143. <input type="hidden" name="kid" value=<?php echo $data['kid'];?>>
  144. </td>
  145. </tr>
  146.  
  147. <tr>
  148. <td></td>
  149. <td>
  150. <?php
  151. $data2=mysqli_query($koneksi, "SELECT * FROM jawaban WHERE sid='$sid' ORDER BY rand()");
  152. while($jawaban=mysqli_fetch_array($data2))
  153. { ?>
  154.  
  155. <div>
  156. <?php $id=$jawaban["sid"]; ?>
  157. <input type="radio" id="pilihan3" name="pilihan3[<?php echo $id; ?>]" value="<?php echo $jawaban['benar'];?>" >
  158. <?php echo $jawaban['jawaban']; ?><br>
  159. </div>
  160.  
  161. <?php
  162. } //akhir perulangan jawaban
  163. ?>
  164. </td>
  165. </tr>
  166.  
  167. <?php
  168. } //akhir perulangan soal
  169. } //tutup else
  170. ?>
  1. <?php
  2. include "koneksi.php";
  3. $kid=$_POST["kid"];
  4.  
  5. if(isset($_POST['submit'])){
  6. $pilihan1=$_POST["pilihan1"]; //post value
  7. $sid=$_POST["id"];
  8. $kid=$_POST["kid"];
  9. $jumlah=$_POST["jumlah"];
  10.  
  11. $score1=0;
  12. $benar1=0;
  13. $kosong1=0;
  14.  
  15. for ($i=0;$i<$jumlah;$i++){
  16. //id nomor soal
  17. $nomor=$sid[$i];
  18.  
  19. //jika user tidak memilih jawaban
  20. if (empty($pilihan1[$nomor])){
  21. $kosong1++;
  22. } else{
  23. //jawaban dari user
  24. $jawaban=$pilihan1[$nomor]; //mengambil value
  25.  
  26. //cocokan jawaban user dengan jawaban di database
  27. $query=mysqli_query($koneksi, "SELECT * FROM jawaban WHERE sid='$nomor' AND '$jawaban'='1' ");
  28. $cek=mysqli_num_rows($query);
  29.  
  30. if($cek){
  31. //jika jawaban cocok (benar)
  32. $benar1++;
  33. }
  34. }
  35.  
  36. //cek salah
  37. $queryjumlahsoal1 = mysqli_query($koneksi, "SELECT * FROM soal INNER JOIN kategori USING (kid) WHERE kid='3' AND id_ujian='ujian'");
  38. $jumlah_soal1 = mysqli_num_rows($queryjumlahsoal1);
  39. $salah1 = $jumlah_soal1-$benar1;
  40. $score1 = $benar1*2/3;
  41. }
  42. }
  43.  
  44. if(isset($_POST['submit'])){
  45. $pilihan2=$_POST["pilihan2"]; //post value
  46. $sid=$_POST["id"];
  47. $kid=$_POST["kid"];
  48. $jumlah=$_POST["jumlah"];
  49.  
  50. $score2=0;
  51. $salah2=0;
  52. $kosong2=0;
  53.  
  54. for ($i=0;$i<$jumlah;$i++){
  55. //id nomor soal
  56. $nomor=$sid[$i];
  57.  
  58. //jika user tidak memilih jawaban
  59. if (empty($pilihan2[$nomor])){
  60. $kosong2++;
  61. } else{
  62. //jawaban dari user
  63. $jawaban=$pilihan2[$nomor]; //mengambil value
  64.  
  65. //cocokan jawaban user dengan jawaban di database
  66. $query=mysqli_query($koneksi, "SELECT * FROM jawaban WHERE sid='$nomor' AND '$jawaban'='1' ");
  67. $cek2=mysqli_num_rows($query);
  68.  
  69. if($cek2){
  70. //jika jawaban cocok (benar)
  71. $salah2++;
  72. }
  73. }
  74.  
  75. //cek salah
  76. $queryjumlahsoal2 = mysqli_query($koneksi, "SELECT * FROM soal INNER JOIN kategori USING (kid) WHERE kid='2' AND id_ujian='ujian'");
  77. $jumlah_soal2 = mysqli_num_rows($queryjumlahsoal2);
  78. $benar2 = $jumlah_soal2-$salah2;
  79. $score2 = $benar2*2/3;
  80. }
  81. }
  82.  
  83. if(isset($_POST['submit'])){
  84. $pilihan3=$_POST["pilihan3"]; //post value
  85. $sid=$_POST["id"];
  86. $kid=$_POST["kid"];
  87. $jumlah=$_POST["jumlah"];
  88.  
  89. $score3=0;
  90. $benar3=0;
  91. $kosong3=0;
  92.  
  93. for ($i=0;$i<$jumlah;$i++){
  94. //id nomor soal
  95. $nomor=$sid[$i];
  96.  
  97. //jika user tidak memilih jawaban
  98. if (empty($pilihan3[$nomor])){
  99. $kosong3++;
  100. } else{
  101. //jawaban dari user
  102. $jawaban=$pilihan3[$nomor]; //mengambil value
  103.  
  104. //cocokan jawaban user dengan jawaban di database
  105. $query=mysqli_query($koneksi, "SELECT * FROM jawaban WHERE sid='$nomor' AND '$jawaban'='1' ");
  106. $cek3=mysqli_num_rows($query);
  107.  
  108. if($cek3){
  109. //jika jawaban cocok (benar)
  110. $benar3++;
  111. }
  112. }
  113.  
  114. //cek salah
  115. $queryjumlahsoal3 = mysqli_query($koneksi, "SELECT * FROM soal INNER JOIN kategori USING (kid) WHERE kid='1' AND id_ujian='ujian'");
  116. $jumlah_soal3 = mysqli_num_rows($queryjumlahsoal3);
  117. $salah3 = $jumlah_soal3-$benar3;
  118. $score3 = $benar3*2/3;
  119. }
  120. }
  121.  
  122. $false = $salah1+$salah2+$salah3;
  123. $right = $benar1+$benar2+$benar3;
  124. $score = ($score1+$score2+$score3)/2;
  125.  
  126. $format=number_format($score,2);
  127.  
  128. if ($score >= 10) {
  129. $hasil = 210;
  130. } else {
  131. $hasil = 200;
  132. }
  133.  
  134.  
  135. ?>
Please login to answer!
Mohon dibantu, ada yang bisa memperbaiki script saya ini. saya bermaksud untuk menampilkan kategori yang berelasi ditabel topik. tapi saya tidak tau script ya, saya sudah coba menggunakan beberapa script yang yang dapat tapi tidak berhasil juga.
  1. <?php
  2. error_reporting(0);
  3. include 'koneksi.php';
  4. session_start();
  5. ?>
  6. <!DOCTYPE html>
  7. <html lang="en">
  8.  
  9. <head>
  10. <meta charset="utf-8">
  11. <meta name="viewport" content="width=device-width, initial-scale=1">
  12. <title>Forum Diskusi</title>
  13.  
  14. <!-- Bootstrap -->
  15. <link href="css/bootstrap.min.css" rel="stylesheet">
  16.  
  17. <!-- Custom -->
  18. <link href="css/custom.css" rel="stylesheet">
  19.  
  20. <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  21. <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  22. <!--[if lt IE 9]>
  23. <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
  24. <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
  25. <![endif]-->
  26.  
  27. <!-- fonts -->
  28. <link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>
  29. <link rel="stylesheet" href="font-awesome-4.0.3/css/font-awesome.min.css">
  30.  
  31. <!-- CSS STYLE-->
  32. <link rel="stylesheet" type="text/css" href="css/style.css" media="screen" />
  33.  
  34. <!-- SLIDER REVOLUTION 4.x CSS SETTINGS -->
  35. <link rel="stylesheet" type="text/css" href="rs-plugin/css/settings.css" media="screen" />
  36.  
  37. </head>
  38. <body>
  39.  
  40. <div class="container-fluid">
  41. <?php include 'header.php'; ?>
  42. <section class="content">
  43. <div class="container">
  44. <br>
  45. </div>
  46.  
  47. <div class="container">
  48.  
  49. <div class="row">
  50. <div class="col-lg-8 col-md-8">
  51.  
  52. <div class="post">
  53. <form action="aksi_tambah_diskusi.php" class="form newtopic" method="post">
  54. <div class="postinfotop">
  55. <h2>Tambah Diskusi</h2>
  56. </div>
  57.  
  58. <!-- acc section -->
  59. <div class="accsection">
  60. <div class="acccap">
  61. <div class="userinfo pull-left">&nbsp;</div>
  62. <div class="clearfix"></div>
  63. </div>
  64. <div class="topwrap">
  65. <div class="userinfo pull-left"> </div>
  66. <div class="posttext pull-left">
  67.  
  68. <div class="row">
  69. <div class="col-lg-4 col-md-6">
  70. Topik
  71. </div>
  72.  
  73. <div class="col-lg-8 col-md-6">
  74. <select name="topik" id="topik" class="form-control" >
  75. <option value="" disabled selected>Pilih Topik</option>
  76. <?php
  77. $kueri_comt = mysql_query("select * from topik");
  78. while($comt = mysql_fetch_array($kueri_comt)){
  79. ?>
  80. <option value="<?php echo $comt[id_topik] ?>"><?php echo $comt[judul_topik] ?></option>
  81. <?php }?>
  82. </select>
  83. </div>
  84. </div>
  85.  
  86. <div class="row">
  87. <div class="col-lg-4 col-md-6">
  88. Kategori
  89. </div>
  90.  
  91. <div class="col-lg-8 col-md-6">
  92. <select name="kategori" id="kategori" class="form-control" >
  93. <option value="" disabled selected>Pilih Kategori</option>
  94. <?php
  95. $kueri_comk = mysql_query("select * from kategori");
  96. while($comk = mysql_fetch_array($kueri_comk)){
  97. ?>
  98. <option value="<?php echo $comk[id_kategori] ?>"><?php echo $comk[nama_kategori] ?></option>
  99. <?php }?>
  100. </select>
  101. </div>
  102. </div>
  103.  
  104. <div class="row">
  105. <div class="col-lg-4 col-md-6">
  106. Judul Diskusi
  107. </div>
  108. <div class="col-lg-8 col-md-6">
  109. <input type="text" name="judul" placeholder="judul_diskusi" class="form-control" />
  110. </div>
  111. </div>
  112.  
  113. <div class="row">
  114. <div class="col-lg-4 col-md-6">
  115. Isi Diskusi
  116. </div>
  117. <div class="col-lg-8 col-md-6">
  118. <textarea type="text" placeholder="Isi Diskusi" class="form-control" id="textarea" name="isi" /></textarea>
  119. </div>
  120. </div>
  121.  
  122.  
  123. </div>
  124. <div class="clearfix"></div>
  125. </div>
  126. </div><!-- acc section END -->
  127. <div class="postinfobot">
  128.  
  129. <div class="notechbox pull-left">
  130. </div>
  131.  
  132. <div class="pull-left lblfch">
  133. </div>
  134.  
  135. <div class="pull-right postreply">
  136. <div class="pull-left"><button type="submit" class="btn btn-primary">Simpan</button></div>
  137. <div class="clearfix"></div>
  138. </div>
  139. <div class="clearfix"></div>
  140. </div>
  141. </form>
  142. </div>
  143.  
  144.  
  145. </div>
  146. <div class="col-lg-4 col-md-4">
  147. <?php include 'sidebar.php' ?>
  148.  
  149.  
  150.  
  151.  
  152. </div>
  153. </div>
  154. </div>
  155.  
  156.  
  157. </section>
  158.  
  159. <?php include 'footer.php' ?>
  160. </div>
  161.  
  162. <!-- get jQuery from the google apis -->
  163. <script type="text/javascript" src="js/jquery.js"></script>
  164.  
  165.  
  166. <!-- SLIDER REVOLUTION 4.x SCRIPTS -->
  167. <script type="text/javascript" src="rs-plugin/js/jquery.themepunch.plugins.min.js"></script>
  168. <script type="text/javascript" src="rs-plugin/js/jquery.themepunch.revolution.min.js"></script>
  169.  
  170. <script src="js/bootstrap.min.js"></script>
  171.  
  172.  
  173. <!-- LOOK THE DOCUMENTATION FOR MORE INFORMATIONS -->
  174. <script type="text/javascript">
  175.  
  176. var revapi;
  177.  
  178. jQuery(document).ready(function() {
  179. "use strict";
  180. revapi = jQuery('.tp-banner').revolution(
  181. {
  182. delay: 15000,
  183. startwidth: 1200,
  184. startheight: 278,
  185. hideThumbs: 10,
  186. fullWidth: "on"
  187. });
  188.  
  189. }); //ready
  190.  
  191. </script>
  192.  
  193. <!-- END REVOLUTION SLIDER -->
  194. </body>
  195.  
  196.  
  197. </html>
Please login to answer!
Mohon dibantu, saya meiliki script seperti dibawah ini. namun setelah di running index.php nya.
muncul error seperti ini. Mohon bisa dibetulkan kesalahan saya dimana?
" Warning: sqlsrv_fetch_array() expects parameter 1 to be resource, string given in D :\xampp\htdocs\testing2\index.php on line 98 "
  1. <html>
  2. <head>
  3. <title>Maintenance Stock</title>
  4. </head>
  5. <body>
  6. <?php
  7. ini_set('display_errors', 1);
  8. error_reporting(~0);
  9.  
  10. $strKeyword = null;
  11.  
  12. if(isset($_POST["txtKeyword"]))
  13. {
  14. $strKeyword = $_POST["txtKeyword"];
  15. }
  16. if(isset($_GET["txtKeyword"]))
  17. {
  18. $strKeyword = $_GET["txtKeyword"];
  19. }
  20. ?>
  21. <form name="frmSearch" method="post" action="<?php echo $_SERVER['SCRIPT_NAME'];?>">
  22. <table width="599" border="1">
  23. <tr>
  24. <th>Keyword
  25. <input name="txtKeyword" type="text" id="txtKeyword" value="<?php echo $strKeyword;?>">
  26. <input type="submit" value="Search"></th>
  27. </tr>
  28. </table>
  29. </form>
  30. <?php
  31. $serverName = "localhost";
  32. $userName = "sa";
  33. $userPassword = "password";
  34. $dbName = "hpm";
  35.  
  36. $connectionInfo = array("Database"=>$dbName, "UID"=>$userName, "PWD"=>$userPassword, "MultipleActiveResultSets"=>true);
  37.  
  38. $conn = sqlsrv_connect( $serverName, $connectionInfo);
  39.  
  40. if( $conn === false ) {
  41. die( print_r( sqlsrv_errors(), true));
  42. }
  43.  
  44. $stmt = "SELECT * FROM mdk_datakendaraan WHERE norangka LIKE '%".$strKeyword."%' ";
  45.  
  46. $params = array();
  47. $options = array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
  48. $query = sqlsrv_query( $conn, $stmt , $params, $options );
  49.  
  50. $num_rows = sqlsrv_num_rows($query);
  51.  
  52. $per_page = 20; // Per Page
  53. $page = 1;
  54.  
  55. if(isset($_GET["Page"]))
  56. {
  57. $page = $_GET["Page"];
  58. }
  59.  
  60. $prev_page = $page-1;
  61. $next_page = $page+1;
  62.  
  63. $row_start = (($per_page*$page)-$per_page);
  64. if($num_rows<=$per_page)
  65. {
  66. $num_pages =1;
  67. }
  68. else if(($num_rows % $per_page)==0)
  69. {
  70. $num_pages =($num_rows/$per_page) ;
  71. }
  72. else
  73. {
  74. $num_pages =($num_rows/$per_page)+1;
  75. $num_pages = (int)$num_pages;
  76. }
  77. $row_end = $per_page * $page;
  78. if($row_end > $num_rows)
  79. {
  80. $row_end = $num_rows;
  81. }
  82.  
  83.  
  84. $stmt2 = " SELECT c.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY norangka) AS RowID,* FROM mdk_datakendaraan WHERE norangka LIKE '%".$strKeyword."%') AS c WHERE c.RowID > $row_start AND c.RowID <= $row_end";
  85.  
  86.  
  87. ?>
  88. <table width="600" border="1">
  89. <tr>
  90. <th width="91"> <div align="center">Kode Tipe </div></th>
  91. <th width="98"> <div align="center">Nama </div></th>
  92. <th width="198"> <div align="center">No. Rangka </div></th>
  93. <th width="97"> <div align="center">No. Mesin </div></th>
  94. <th width="59"> <div align="center">Nama Sales </div></th>
  95. <th width="71"> <div align="center">Nama Running </div></th>
  96. </tr>
  97. <?php
  98. while($row = sqlsrv_fetch_array($stmt2))
  99.  
  100. {
  101. ?>
  102.  
  103. <tr>
  104. <td><div align="center"><?php echo $row["kode_tipe"];?></div></td>
  105. <td><?php echo $row["nama"];?></td>
  106. <td><?php echo $row["norangka"];?></td>
  107. <td><div align="center"><?php echo $row["nomesin"];?></div></td>
  108. <td align="right"><?php echo $row["nama_sales_mdk"];?></td>
  109. <td align="right"><?php echo $row["nama_cust_mdk"];?></td>
  110. </tr>
  111. <?php
  112. }
  113. ?>
  114. </table>
  115. <br>
  116. Total <?php echo $num_rows;?> Record : <?php echo $num_pages;?> Page :
  117. <?php
  118. if($prev_page)
  119. {
  120. echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$prev_page&txtKeyword=$strKeyword'><< Back</a> ";
  121. }
  122.  
  123. for($i=1; $i<=$num_pages; $i++){
  124. if($i != $page)
  125. {
  126. echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&txtKeyword=$strKeyword'>$i</a> ]";
  127. }
  128. else
  129. {
  130. echo "<b> $i </b>";
  131. }
  132. }
  133. if($page!=$num_pages)
  134. {
  135. echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$next_page&txtKeyword=$strKeyword'>Next>></a> ";
  136. }
  137. sqlsrv_close($conn);
  138. ?>
  139. </body>
  140. </html>
  141.  
Please login to answer!
User Paling Aktif Bulan Lalu

Rey Paksi Manggala

Rey Paksi Manggala

Point Bulan Lalu: 6