似乎我的代码错了。我使用方法GET并在其页面上传递变量。这是我的表格代码。
<form method="get" action="?nama'">
<div class="input-group">
<span class="input-group-addon" id="basic-addon1"><i class="fa fa-search"></i></span>
<input type="text" class="form-control" name="nama" placeholder="Cari berdasarkan Nama Lengkap Pendaftar" aria-describedby="basic-addon1">
<span class="input-group-btn">
<button class="btn btn-success" type="submit">Go!</button>
</span>
</div>
</form>
这适用于GET方法。我正在使用表来写结果。
<div class="table-responsive">
<table class="table table-bordered table-hover">
<tr style="font-weight: bold; text-align: center;">
<td> No. </td>
<td> ID Pendaftaran </td>
<td> Nama Lengkap </td>
<td> Jenis Kelamin </td>
<td> Asal Sekolah </td>
<td> Tanggal Daftar </td>
<td> Pengembalian Form </td>
</tr>
<?php
if (isset($_GET['nama'])) {
$no = 1;
$nama = $_GET['nama'];
$query = mysqli_query($koneksi, "SELECT * FROM pendaftar WHERE NAMAPENDAFTAR LIKE '%".$nama."'%'");
while ($loop = mysqli_fetch_array($query)) {
?>
<tr style="text-align: center;">
<td> <?php echo $no; ?> </td>
<td> <?php echo $loop['IDPENDAFTAR']; ?> </td>
<td> <?php echo $loop['NAMAPENDAFTAR']; ?> </td>
<td> <?php echo $loop['JENISKELAMIN']; ?> </td>
<td><?php echo $loop['SEKOLAHASAL']; ?> </td>
<td><?php echo date('d-m-Y', strtotime($loop['TANGGALDAFTAR'])); ?> </td>
<td><button type="button" name="kembali" class="btn btn-default" data-toggle="modal" data-target="#myModal">Form Kembali</button></td>
</tr>
<?php
$no++;
}
}
else {
$no = 1;
$query1 = mysqli_query($koneksi, "SELECT * FROM pendaftar");
while ($loop = mysqli_fetch_array($query1)) {
?>
<tr style="text-align: center;">
<td> <?php echo $no; ?> </td>
<td> <?php echo $loop['IDPENDAFTAR']; ?> </td>
<td> <?php echo $loop['NAMAPENDAFTAR']; ?> </td>
<td> <?php echo $loop['JENISKELAMIN']; ?> </td>
<td><?php echo $loop['SEKOLAHASAL']; ?> </td>
<td><?php echo date('d-m-Y', strtotime($loop['TANGGALDAFTAR'])); ?> </td>
<td><button type="button" name="kembali" class="btn btn-default" data-toggle="modal" data-target="#myModal">Form Kembali</button></td>
</tr>
<?php
$no++;
}
}
?>
</table>
</div>
这样的错误。
警告:mysqli_fetch_array()期望参数1为mysqli_result, 第126行的C:\ xampp \ htdocs \ WebKP \ admin-site.php中给出的布尔值 但是,当我试图查询我的phpmyadmin时,它有结果。
答案 0 :(得分:1)
这里有SQL语法错误
$query = mysqli_query($koneksi, "SELECT * FROM pendaftar WHERE NAMAPENDAFTAR LIKE '%".$nama."'%'");
使用以下代码
$query = mysqli_query($koneksi, "SELECT * FROM pendaftar WHERE NAMAPENDAFTAR LIKE '%".$nama."%'")