I have a table consists of three columns :
id
author
message
Once the user clicks on the More
Button the button passes the Count
parameter to .load
function. And then new data should display but it
displays a blank page.What am i doing wrong?
this is index.php:
<div id="comments">
<?php
$v=$db->prepare('select * from comments limit 2');
$v->execute();
$data=$v->fetchAll(PDO::FETCH_ASSOC);
foreach ($data as $row) {
echo "<div>".$row['author']."</div>";
echo "<div>".$row['message']."</div>";
echo "</br>";
}
?>
</div>
<input type="submit" name="" id="submit" value="More">
</body>
</html>
<script type="text/javascript">
$(document).ready(function(){
var commentCount=2;
$('#submit').click(function(){
commentCount=commentCount+2;
$('#comments').load('loadComments.php',{count:commentCount});
});
});
</script>
this is loadComments.php:
<?php
$db=new PDO('mysql:host=localhost;dbname=ajax',"root","");
$newCount=$_POST['count'];
$ex=$db->prepare('select * from comments limit $newCount');
$ex->execute();
$data=$ex->fetchALL(PDO::FETCH_ASSOC);
foreach ($data as $row) {
echo "<div>".$row['author']."</div>";
echo "<div>".$row['message']."</div>";
echo "</br>";
}
?>
EDİT:
If I use this way everything is ok.
$v=$db->prepare('select * from comments limit 3');
But I have checked count
parametre inside loadComment.php
echo $newCount;
and I am able to get the value Its funny