Mohon bantuannya, saya bingung melakukan get textboxt sebagai nama tabel database yang ingin digunakan.
<?php //proses-ajax.php
include 'koneksi.php';
$nim = $_GET['nim'];
$nama = "mahasiswa";//mau dibikin $nama = $_GET['namatabel'];
$query = mysqli_query($koneksi, "select * from $nama where nim='$nim'");
$mahasiswa = mysqli_fetch_array($query);
$data = array(
            'jurusan'   =>  $mahasiswa['jurusan'],
            'alamat'    =>  $mahasiswa['alamat'],);
 echo json_encode($data);
?>

ini form ajaxnya
<!DOCTYPE html> <!--form-ajax.php-->
<html>
    <head>
        <title>Ajax Jquery - Belajarphp.net</title>
    </head>
    <body>
        <form action="">
            <table>
                <tr><td>NIM</td><td><input type="text" onkeyup="isi_otomatis()" id="nim"></td></tr>
                <tr><td>NAMA TABEL</td><td><input type="text" id="namatabel"></td></tr>
                <tr><td>JURUSAN</td><td><input type="text" id="jurusan"></td></tr>
                <tr><td>ALAMAT</td><td><input type="text" id="alamat"></td></tr>
            </table>
        </form>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
        <script type="text/javascript">
            function isi_otomatis(){
                var nimi = $("#nim").val();
                $.ajax({
                    url: 'proses-ajax.php',
                    data:"nim="+nimi,
                }).success(function (data) {
                    var json = data,
                    obj = JSON.parse(json);
                    $('#jurusan').val(obj.jurusan);
                    $('#alamat').val(obj.alamat);
                });
            }
        </script>
    </body>
</html>

Terima kasih sebelumnnya

Lihat semua 1 jawaban

Silahkan login untuk menjawab!
<?php
                                      //include file koneksi ke database
                                      include('config/koneksi.php');
                                    ?>
                                      

                                    <?php
                          
                                      $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());
                                      $jumlah=mysqli_num_rows($query); // jumlah baris soal yang dipilih
                          
                                      //cek, apakah hasil query mendapatkan hasil atau tidak
                                      //jika data kosong
                                      if(mysqli_num_rows($query) == 0){
                                          echo '<tr><td colspan="6">Tidak ada data!</td></tr>';
                                      } else{ // jika data ada
                                          $no = 1;
                                          while($data = mysqli_fetch_assoc($query)){
                                    ?>
               
                                    <tr>
                                        <td><?php echo $no++; ?></td>
                                        <td>
                                            <?php 
                                                echo $data['soal']; 
                                                $sid=$data['sid'];
                                                $id_ujian=$data['id_ujian'];
                                            ?>

                                            <input type="hidden" name="id[]" value=<?php echo $sid; ?>>
                                            <input type="hidden" name="id_ujian" value=<?php echo $id_ujian; ?>>
                                            <input type="hidden" name="jumlah" value=<?php echo $jumlah;?>>
                                            <input type="hidden" name="kid" value=<?php echo $data['kid'];?>>
                                        </td>   
                                    </tr>
               
                                    <tr>
                                        <td></td>
                                        <td>
                                            <?php
                                                $data2=mysqli_query($koneksi, "SELECT * FROM jawaban WHERE sid='$sid' ORDER BY rand()");
                                                while($jawaban=mysqli_fetch_array($data2))
                                            { ?>
                                            
                                            <div>
                                                <?php $id=$jawaban["sid"]; ?>
                                                <input type="radio" id="pilihan1" name="pilihan1[<?php echo $id; ?>]" value="<?php echo $jawaban['benar'];?>" >
                                                <?php echo $jawaban['jawaban']; ?><br>
                                            </div>
                                            
                                            <?php 
                                            } //akhir perulangan jawaban
                                            ?>
                                        </td>   
                                    </tr>

                                    <?php 
                                    } //akhir perulangan soal
                                    } //tutup else
                                    ?>

                                    <?php
                          
                                      $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());
                                      $jumlah=mysqli_num_rows($query); // jumlah baris soal yang dipilih
                          
                                      //cek, apakah hasil query mendapatkan hasil atau tidak
                                      //jika data kosong
                                      if(mysqli_num_rows($query) == 0){
                                          echo '<tr><td colspan="6">Tidak ada data!</td></tr>';
                                      } else{ // jika data ada
                                          $no = 1;
                                          while($data = mysqli_fetch_assoc($query)){
                                    ?>
               
                                    <tr>
                                        <td><?php echo $no++; ?></td>
                                        <td>
                                            <?php 
                                                echo $data['soal']; 
                                                $sid=$data['sid'];
                                                $id_ujian=$data['id_ujian'];
                                            ?>

                                            <input type="hidden" name="id[]" value=<?php echo $sid; ?>>
                                            <input type="hidden" name="id_ujian" value=<?php echo $id_ujian; ?>>
                                            <input type="hidden" name="jumlah" value=<?php echo $jumlah;?>>
                                            <input type="hidden" name="kid" value=<?php echo $data['kid'];?>>
                                        </td>   
                                    </tr>
               
                                    <tr>
                                        <td></td>
                                        <td>
                                            <?php
                                                $data2=mysqli_query($koneksi, "SELECT * FROM jawaban WHERE sid='$sid' ORDER BY rand()");
                                                while($jawaban=mysqli_fetch_array($data2))
                                            { ?>
                                            
                                            <div>
                                                <?php $id=$jawaban["sid"]; ?>
                                                <input type="radio" id="pilihan2" name="pilihan2[<?php echo $id; ?>]" value="<?php echo $jawaban['benar'];?>" >
                                                <?php echo $jawaban['jawaban']; ?><br>
                                            </div>
                                            
                                            <?php 
                                            } //akhir perulangan jawaban
                                            ?>
                                        </td>   
                                    </tr>

                                    <?php 
                                    } //akhir perulangan soal
                                    } //tutup else
                                    ?>

                                    <?php
                          
                                      $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());
                                      $jumlah=mysqli_num_rows($query); // jumlah baris soal yang dipilih
                          
                                      //cek, apakah hasil query mendapatkan hasil atau tidak
                                      //jika data kosong
                                      if(mysqli_num_rows($query) == 0){
                                          echo '<tr><td colspan="6">Tidak ada data!</td></tr>';
                                      } else{ // jika data ada
                                          $no = 1;
                                          while($data = mysqli_fetch_assoc($query)){
                                    ?>
               
                                    <tr>
                                        <td><?php echo $no++; ?></td>
                                        <td>
                                            <?php 
                                                echo $data['soal']; 
                                                $sid=$data['sid'];
                                                $id_ujian=$data['id_ujian'];
                                            ?>

                                            <input type="hidden" name="id[]" value=<?php echo $sid; ?>>
                                            <input type="hidden" name="id_ujian" value=<?php echo $id_ujian; ?>>
                                            <input type="hidden" name="jumlah" value=<?php echo $jumlah;?>>
                                            <input type="hidden" name="kid" value=<?php echo $data['kid'];?>>
                                        </td>   
                                    </tr>
               
                                    <tr>
                                        <td></td>
                                        <td>
                                            <?php
                                                $data2=mysqli_query($koneksi, "SELECT * FROM jawaban WHERE sid='$sid' ORDER BY rand()");
                                                while($jawaban=mysqli_fetch_array($data2))
                                            { ?>
                                            
                                            <div>
                                                <?php $id=$jawaban["sid"]; ?>
                                                <input type="radio" id="pilihan3" name="pilihan3[<?php echo $id; ?>]" value="<?php echo $jawaban['benar'];?>" >
                                                <?php echo $jawaban['jawaban']; ?><br>
                                            </div>
                                            
                                            <?php 
                                            } //akhir perulangan jawaban
                                            ?>
                                        </td>   
                                    </tr>

                                    <?php 
                                    } //akhir perulangan soal
                                    } //tutup else
                                    ?>
<?php 
	   									include "koneksi.php";
     									$kid=$_POST["kid"];

       								if(isset($_POST['submit'])){
                      $pilihan1=$_POST["pilihan1"]; //post value
                      $sid=$_POST["id"];
                      $kid=$_POST["kid"];
                      $jumlah=$_POST["jumlah"];
      
                      $score1=0;
                      $benar1=0;
                      $kosong1=0;

                      for ($i=0;$i<$jumlah;$i++){
                        //id nomor soal
                        $nomor=$sid[$i];
        
                        //jika user tidak memilih jawaban
                        if (empty($pilihan1[$nomor])){
                          $kosong1++;
                        } else{
                          //jawaban dari user
                          $jawaban=$pilihan1[$nomor]; //mengambil value 
          
                          //cocokan jawaban user dengan jawaban di database
                          $query=mysqli_query($koneksi, "SELECT * FROM jawaban WHERE sid='$nomor' AND '$jawaban'='1' ");
                          $cek=mysqli_num_rows($query);
                  
                          if($cek){
                            //jika jawaban cocok (benar)
                                  $benar1++;
                          } 
                        } 
                            
                            //cek salah
                              $queryjumlahsoal1 = mysqli_query($koneksi, "SELECT * FROM soal INNER JOIN kategori USING (kid) WHERE kid='3' AND id_ujian='ujian'");
                              $jumlah_soal1 = mysqli_num_rows($queryjumlahsoal1);
                              $salah1 = $jumlah_soal1-$benar1;
                              $score1 = $benar1*2/3;
                        }
                      }

                      if(isset($_POST['submit'])){
                      $pilihan2=$_POST["pilihan2"]; //post value
                      $sid=$_POST["id"];
                      $kid=$_POST["kid"];
                      $jumlah=$_POST["jumlah"];
      
                      $score2=0;
                      $salah2=0;
                      $kosong2=0;

                      for ($i=0;$i<$jumlah;$i++){
                        //id nomor soal
                        $nomor=$sid[$i];
        
                        //jika user tidak memilih jawaban
                        if (empty($pilihan2[$nomor])){
                          $kosong2++;
                        } else{
                          //jawaban dari user
                          $jawaban=$pilihan2[$nomor]; //mengambil value 
          
                          //cocokan jawaban user dengan jawaban di database
                          $query=mysqli_query($koneksi, "SELECT * FROM jawaban WHERE sid='$nomor' AND '$jawaban'='1' ");
                          $cek2=mysqli_num_rows($query);
                  
                          if($cek2){
                            //jika jawaban cocok (benar)
                                  $salah2++;
                          } 
                        } 
                            
                            //cek salah
                              $queryjumlahsoal2 = mysqli_query($koneksi, "SELECT * FROM soal INNER JOIN kategori USING (kid) WHERE kid='2' AND id_ujian='ujian'");
                              $jumlah_soal2 = mysqli_num_rows($queryjumlahsoal2);
                              $benar2 = $jumlah_soal2-$salah2;
                              $score2 = $benar2*2/3;
                        }
                      }

                      if(isset($_POST['submit'])){
                      $pilihan3=$_POST["pilihan3"]; //post value
                      $sid=$_POST["id"];
                      $kid=$_POST["kid"];
                      $jumlah=$_POST["jumlah"];
      
                      $score3=0;
                      $benar3=0;
                      $kosong3=0;

                      for ($i=0;$i<$jumlah;$i++){
                        //id nomor soal
                        $nomor=$sid[$i];
        
                        //jika user tidak memilih jawaban
                        if (empty($pilihan3[$nomor])){
                          $kosong3++;
                        } else{
                          //jawaban dari user
                          $jawaban=$pilihan3[$nomor]; //mengambil value 
          
                          //cocokan jawaban user dengan jawaban di database
                          $query=mysqli_query($koneksi, "SELECT * FROM jawaban WHERE sid='$nomor' AND '$jawaban'='1' ");
                          $cek3=mysqli_num_rows($query);
                  
                          if($cek3){
                            //jika jawaban cocok (benar)
                                  $benar3++;
                          } 
                        } 
                            
                            //cek salah
                              $queryjumlahsoal3 = mysqli_query($koneksi, "SELECT * FROM soal INNER JOIN kategori USING (kid) WHERE kid='1' AND id_ujian='ujian'");
                              $jumlah_soal3 = mysqli_num_rows($queryjumlahsoal3);
                              $salah3 = $jumlah_soal3-$benar3;
                              $score3 = $benar3*2/3;
                        }
                      }

                      $false = $salah1+$salah2+$salah3;
                      $right = $benar1+$benar2+$benar3;
                      $score = ($score1+$score2+$score3)/2;

                      $format=number_format($score,2);
                      
                      if ($score >= 10) {
                        $hasil = 210;
                      } else {
                        $hasil = 200;
                      }

                      
                  ?>
Silahkan login untuk menjawab!
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.
<?php 
error_reporting(0);
include 'koneksi.php';
session_start();
?>
<!DOCTYPE html>
<html lang="en">
    
<head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Forum Diskusi</title>

        <!-- Bootstrap -->
        <link href="css/bootstrap.min.css" rel="stylesheet">

        <!-- Custom -->
        <link href="css/custom.css" rel="stylesheet">

        <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
        <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
          <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
          <![endif]-->

        <!-- fonts -->
        <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'>
        <link rel="stylesheet" href="font-awesome-4.0.3/css/font-awesome.min.css">

        <!-- CSS STYLE-->
        <link rel="stylesheet" type="text/css" href="css/style.css" media="screen" />

        <!-- SLIDER REVOLUTION 4.x CSS SETTINGS -->
        <link rel="stylesheet" type="text/css" href="rs-plugin/css/settings.css" media="screen" />

    </head>
    <body>

        <div class="container-fluid">
        <?php include 'header.php'; ?>
          <section class="content">
                <div class="container">
                    <br>
                </div>

                <div class="container">

				<div class="row">
                        <div class="col-lg-8 col-md-8">
						
				<div class="post">
				<form action="aksi_tambah_diskusi.php" class="form newtopic" method="post">
					<div class="postinfotop">
						<h2>Tambah Diskusi</h2>
					</div>
					
					<!-- acc section -->
					<div class="accsection">
						<div class="acccap">
							<div class="userinfo pull-left">&nbsp;</div>
							<div class="clearfix"></div>
						</div>
						<div class="topwrap">
							<div class="userinfo pull-left"> </div>
							<div class="posttext pull-left">
							
								<div class="row">
									<div class="col-lg-4 col-md-6">
									 Topik
									</div>
								
								<div class="col-lg-8 col-md-6">
									<select name="topik" id="topik"  class="form-control" >
										<option value="" disabled selected>Pilih Topik</option>
										<?php
										$kueri_comt = mysql_query("select * from topik");
										while($comt = mysql_fetch_array($kueri_comt)){
										?>
										<option value="<?php echo $comt[id_topik] ?>"><?php echo $comt[judul_topik] ?></option>
										<?php }?>
									</select>
								</div>
								</div>
								
								<div class="row">
									<div class="col-lg-4 col-md-6">
									 Kategori
									</div>
								
								<div class="col-lg-8 col-md-6">
									<select name="kategori" id="kategori"  class="form-control" >
										<option value="" disabled selected>Pilih Kategori</option>
										<?php
										$kueri_comk = mysql_query("select * from kategori");
										while($comk = mysql_fetch_array($kueri_comk)){
										?>
										<option value="<?php echo $comk[id_kategori] ?>"><?php echo $comk[nama_kategori] ?></option>
										<?php }?>
									</select>
								</div>
								</div>
								
								<div class="row">
								<div class="col-lg-4 col-md-6">
									 Judul Diskusi
									</div>
									<div class="col-lg-8 col-md-6">
										<input type="text" name="judul" placeholder="judul_diskusi" class="form-control" />
									</div>
								</div>
								
								<div class="row">
									<div class="col-lg-4 col-md-6">
									Isi Diskusi
									</div>
									<div class="col-lg-8 col-md-6">
										<textarea type="text" placeholder="Isi Diskusi" class="form-control" id="textarea" name="isi" /></textarea>
									</div>
								</div>
								

							</div>
							<div class="clearfix"></div>
						</div>  
					</div><!-- acc section END -->
					<div class="postinfobot">

					<div class="notechbox pull-left">
					</div>

					<div class="pull-left lblfch">
					</div>

					<div class="pull-right postreply">
						<div class="pull-left"><button type="submit" class="btn btn-primary">Simpan</button></div>
						<div class="clearfix"></div>
					</div>
					<div class="clearfix"></div>
				</div>
					</form>
					</div>

						
		                </div>
                        <div class="col-lg-4 col-md-4">
                        <?php include 'sidebar.php' ?>

                           


                        </div>
                    </div>
                </div>


            </section>

            <?php include 'footer.php' ?>
        </div>

        <!-- get jQuery from the google apis -->
        <script type="text/javascript" src="js/jquery.js"></script>
 

        <!-- SLIDER REVOLUTION 4.x SCRIPTS  -->
        <script type="text/javascript" src="rs-plugin/js/jquery.themepunch.plugins.min.js"></script>
        <script type="text/javascript" src="rs-plugin/js/jquery.themepunch.revolution.min.js"></script>

        <script src="js/bootstrap.min.js"></script>


        <!-- LOOK THE DOCUMENTATION FOR MORE INFORMATIONS -->
        <script type="text/javascript">
            
            var revapi;

            jQuery(document).ready(function() {
                "use strict";
                revapi = jQuery('.tp-banner').revolution(
                        {
                            delay: 15000,
                            startwidth: 1200,
                            startheight: 278,
                            hideThumbs: 10,
                            fullWidth: "on"
                        });

            });	//ready

        </script>

        <!-- END REVOLUTION SLIDER -->
    </body>


</html>
Silahkan login untuk menjawab!
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 "
<html>
<head>
<title>Maintenance Stock</title>
</head>
<body>
<?php
	ini_set('display_errors', 1);
	error_reporting(~0);

	$strKeyword = null;

	if(isset($_POST["txtKeyword"]))
	{
		$strKeyword = $_POST["txtKeyword"];
	}
	if(isset($_GET["txtKeyword"]))
	{
		$strKeyword = $_GET["txtKeyword"];
	}
?>
<form name="frmSearch" method="post" action="<?php echo $_SERVER['SCRIPT_NAME'];?>">
  <table width="599" border="1">
    <tr>
      <th>Keyword
      <input name="txtKeyword" type="text" id="txtKeyword" value="<?php echo $strKeyword;?>">
      <input type="submit" value="Search"></th>
    </tr>
  </table>
</form>
<?php
	$serverName = "localhost";
	$userName = "sa";
	$userPassword = "password";
	$dbName = "hpm";

	$connectionInfo = array("Database"=>$dbName, "UID"=>$userName, "PWD"=>$userPassword, "MultipleActiveResultSets"=>true);

	$conn = sqlsrv_connect( $serverName, $connectionInfo);

	if( $conn === false ) {
		die( print_r( sqlsrv_errors(), true));
	}

	$stmt = "SELECT * FROM mdk_datakendaraan WHERE norangka LIKE '%".$strKeyword."%' ";
	
	$params = array();
	$options =  array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
	$query = sqlsrv_query( $conn, $stmt , $params, $options );

	$num_rows = sqlsrv_num_rows($query);

	$per_page = 20;   // Per Page
	$page  = 1;
	
	if(isset($_GET["Page"]))
	{
		$page = $_GET["Page"];
	}

	$prev_page = $page-1;
	$next_page = $page+1;

	$row_start = (($per_page*$page)-$per_page);
	if($num_rows<=$per_page)
	{
		$num_pages =1;
	}
	else if(($num_rows % $per_page)==0)
	{
		$num_pages =($num_rows/$per_page) ;
	}
	else
	{
		$num_pages =($num_rows/$per_page)+1;
		$num_pages = (int)$num_pages;
	}
	$row_end = $per_page * $page;
	if($row_end > $num_rows)
	{
		$row_end = $num_rows;
	}


	$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";

	
?>
<table width="600" border="1">
  <tr>
    <th width="91"> <div align="center">Kode Tipe </div></th>
    <th width="98"> <div align="center">Nama </div></th>
    <th width="198"> <div align="center">No. Rangka </div></th>
    <th width="97"> <div align="center">No. Mesin </div></th>
    <th width="59"> <div align="center">Nama Sales </div></th>
    <th width="71"> <div align="center">Nama Running </div></th>
  </tr>
<?php
while($row = sqlsrv_fetch_array($stmt2))

{
?>
  	
<tr>
    <td><div align="center"><?php echo $row["kode_tipe"];?></div></td>
    <td><?php echo $row["nama"];?></td>
    <td><?php echo $row["norangka"];?></td>
    <td><div align="center"><?php echo $row["nomesin"];?></div></td>
    <td align="right"><?php echo $row["nama_sales_mdk"];?></td>
    <td align="right"><?php echo $row["nama_cust_mdk"];?></td>
  </tr>
<?php
}
?>
</table>
<br>
Total <?php echo $num_rows;?> Record : <?php echo $num_pages;?> Page :
<?php
if($prev_page)
{
	echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$prev_page&txtKeyword=$strKeyword'><< Back</a> ";
}

for($i=1; $i<=$num_pages; $i++){
	if($i != $page)
	{
		echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&txtKeyword=$strKeyword'>$i</a> ]";
	}
	else
	{
		echo "<b> $i </b>";
	}
}
if($page!=$num_pages)
{
	echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$next_page&txtKeyword=$strKeyword'>Next>></a> ";
}
sqlsrv_close($conn);
?>
</body>
</html>
Silahkan login untuk menjawab!

Mohon Bantuan

_FB_NAME_ · Nov 23, 2016
maaf gan, saya mau tanya, semisal saya punya tabel akun (id_akun (01,02), jenis_akun (pendapatan,pengeluaran), keterangan (kas desa,pembetulan jalan)).
di form saya punya 2 combobox, combobox 1 ada data: bukti bank masuk, bukti bank keluar (bukan data dinamis). semisal pada combobox 1 saya pilih bukti bank masuk, maka pada combobox 2 akan menampilkan data hanya berdasarkan jenis_akun pendapatan. jika combobox 1 saya pilih bukti bank keluar, maka pada combobox 2 hanya akan menampilkan data jenis_akun pengeluaran.
Moho bantuannya gan terima kasih
Silahkan login untuk menjawab!