BR
asked on
trying to learn How to Make Load More Results From Database using jQuery,Ajax,PHP and MySQL
Dear Experts, I'm trying to learn How to Make Load More Results From Database using jQuery,Ajax,PHP and MySQL
I found this simple code on the web which is suppose be working but I have the below error.
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, bool given in ....
I tried a few things but it didn't work. What do you suggest I should do?
On the top of my two pages I have database connection, and my code is :
on my seccond page which is getrecord.php
I found this simple code on the web which is suppose be working but I have the below error.
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, bool given in ....
I tried a few things but it didn't work. What do you suggest I should do?
On the top of my two pages I have database connection, and my code is :
<?php
.......
$con = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE);
?>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#load").click(function () {
loadmore();
});
});
function loadmore()
{
var val = document.getElementById("result_no").value;
$.ajax({
type: 'post',
url: 'getrecord.php',
data: {
getresult: val
},
success: function (response) {
var content = document.getElementById("result_para");
content.innerHTML = content.innerHTML + response;
document.getElementById("result_no").value = Number(val) + 2;
}
});
}
</script>
</head>
<body>
<center>
<p id="heading">How to Make Load More Results From Database using jQuery,Ajax,PHP and MySQL</p>
<div id="content">
<div id="result_para">
<?php
$select = mysqli_query($con, "SELECT * FROM siparis limit 0,2");
while ($row = mysqli_fetch_assoc($select)) {
echo "<p class='result'>" . $row['_key'] . "<br>" . $row['uid'] . "</p>";
}
?>
<input type="hidden" id="result_no" value="2">
<input type="button" id="load" value="Load More Results">
</div>
</div>
</center>
</body>
</html>
on my seccond page which is getrecord.php
.....
$con = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE);
$no = $_POST['getresult'];
$select = mysqli_query($con,"SELECT * siparis LIMIT $no,2");
while ($row = mysqli_fetch_assoc($select)) {
echo "<p class='result'>" . $row['_key'] . "<br>" . $row['uid'] . "</p>";
}
ASKER
Dear Dave Baldwin,
I have it on top of my page.
$con = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE);
my errror message is : Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, bool given in ....
I have it on top of my page.
$con = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE);
my errror message is : Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, bool given in ....
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you so much Chris Stanyon,
That solved my problem.
Now, It brings me the data, however, it only brings it once,
when I click it load more, it doesn't.
it brings it only once.
what do you suggest I should do?
That solved my problem.
Now, It brings me the data, however, it only brings it once,
when I click it load more, it doesn't.
it brings it only once.
what do you suggest I should do?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You are great Chris Stanyon,
thank you very much
thank you very much
You're welcome
Open in new window
https://www.php.net/manual/en/function.mysqli-connect.php
Also look here.
https://www.php.net/manual/en/mysqli-result.fetch-assoc.php