注意:未定义的索引:produk_id_terakhir in 第5行的E:\ xampp \ htdocs \ bootstrap \ load_data.php
警告:mysqli_num_rows()期望参数1为mysqli_result, 第7行的E:\ xampp \ htdocs \ bootstrap \ load_data.php中给出的布尔值
此load_more.php
<?php
$connect = mysqli_connect("localhost", "root", "", "rumahta_app");
$sql = "SELECT * FROM produk LIMIT 2";
$result = mysqli_query($connect, $sql);
$produk_id = '';
?>
<html>
<head>
<title>Load More</title>
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"></link>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<br />
<br />
<br />
<div class="table-responsive">
<table class="table table-bordered" id="load_more">
<?php
while($row = mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row["nama_produk"]; ?></td>
</tr>
<?php
$produk_id = $row["produk_id"];
}
?>
<tr id="remove_row">
<td><button name="btn_more" type="button" id="btn_more" data-vid="<?php echo $produk_id; ?>" class="btn btn-success form-control">More</button></td>
</tr>
</table>
</div>
</div>
</body>
</html>
<script>
$(document).ready(function(){
$(document).on('click','#btn_more', function(){
var produk_id_terakhir = $(this).data("vid");
$('##btn_more').html("Loading...");
$.ajax({
url:"load_data.php",
method:"POST",
data:{produk_id_terakhir:last_produk_id_terakhir},
dataType:"text",
success:function(data)
{
if(data != '')
{
$('#remove_row').remove();
$('#load_more').append(data);
}else{
$('btn_more').html("No Data");
}
}
});
});
});
</script>
和这个load_data.php
<?php
$connect = mysqli_connect("localhost", "root", "", "");
$output = '';
$produk_id = '';
$sql = "SELECT * FROM produk WHERE produk_id > " .$_POST["produk_id_terakhir"]." LIMIT 2";
$result = mysqli_query($connect, $sql);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
$produk_id = $row["produk_id"];
$output .= '
<tbody>
<tr>
<td> '.$row['nama_produk'].' </td>
</tr>
</tbody>
';
}
$output .='
<tbody><tr id="remove_row">
<button name="btn_more" type="button" id="btn_more" data-vid="'. $produk_id .'" class="btn btn-success form-control">More</button>
</tr></tbody>
';
echo $output;
}
?>
答案 0 :(得分:1)
用这个替换第4行:
if (isset ($_POST["produk_id_terakhir"])) {
$sql = "SELECT * FROM produk WHERE produk_id > " .mysqli_real_escape_string ($_POST["produk_id_terakhir"])." LIMIT 2";
} else {
// to do: exit() or print error message
}