continuous scrolling. AJAX, PHP, JAVASCRIPT, MYSQL -
i creating forum. so, there "order by" dropdown box i.e select tag in html. user selects order time or like, etc. ajax function called dynamically brings content page mysql database.
select menu
<select name="orderby" onchange="showposts(this.value)"> <option value="1" selected>by time</option> <option value="2">by genuine count</option> <option value="3">by dubious count</option> </select>
showposts function
function showposts(str){ orderby=str; if (window.xmlhttprequest) { // code ie7+, firefox, chrome, opera, safari xmlhttp=new xmlhttprequest(); } else { // code ie6, ie5 xmlhttp=new activexobject("microsoft.xmlhttp"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readystate==4 && xmlhttp.status==200) { document.getelementbyid("postsdiv").innerhtml=xmlhttp.responsetext; } } xmlhttp.open("get","showposts.php?q="+str,true); xmlhttp.send(); }
showposts.php page
$sql = "select * posts order date desc "; $result = $connection->query($sql); $username=$_session['username']; while($row = $result->fetch_assoc()) { echo "<span id='postspan".$row['id']."' name='postspan".$row['id']."' >"; echo "<span id='editspan".$row['id']."' name='editspan".$row['id']."' >"; echo "-----------------------------------</br>"; echo "-----------------------------------</br>"; echo "posted by: ".$row['user']."    "; echo "time: ".$row['date']."</br>"; echo "<span id=genuinecount".$row['id'].">genuine count: ".$row['genuine']."; echo "<span id=dubiouscount".$row['id'].">dubious count: ".$row['dubious']."</span>"; echo "</br>------------------------ </br>"; echo "subject: ".$row['subject']."</br>"; echo "post: ".$row['post'].'<br />';
}
problem so, problem here is, want use continuous scroll option 1 used in facebook. javascripts , jquery libraries saw use logic when user scrolls down page, javascript places content after that. but, here running while loop brings data database @ time. so, couldn't implement javascript code. so, there thing achieve continuous scroll, there possibility break while loop or retrieving entire data , display part part or that?
javascript scrolling
function yhandler(){ var wrap=document.getelementbyid('postsdiv'); var contentheight=wrap.offsetheight; var yoffset=window.pageyoffset; var y=yoffset+window.innerheight; if(y>=contentheight){ showposts(); } } window.onscroll=yhandler();
use pdo class built php , query database return rows array of stdclass objects. use pdostatement::fetchobject() loop through array
Comments
Post a Comment