acctman Posted October 28, 2008 Share Posted October 28, 2008 does anyone have a working example of an ajax pagination with mysql? i've already looked through google and they all reference the same dynamicdrive example in which it does show much as to how to do it. i just want to see a script / example that 1. queries a mysql db, 2. displays the info onto a page with pagination 3. is down with ajax so the page doesnt change. i'm going to be displaying images so any jquery grids or table classes wont help. Quote Link to comment Share on other sites More sharing options...
zenag Posted October 30, 2008 Share Posted October 30, 2008 u can try it with prototype.js...here's an example .try it out... main.php <? $con=mysql_connect("localhost","root",""); mysql_select_db("db",$con); $sql=mysql_query("select fieldname,id from table1"); ?><script type="text/javascript" src="prototype.js"></script> <table><tr><td> <div id="display"></div> <select onChange="ajaxRequest('ajax.php',this.value,0)"name=""><? while($row=mysql_fetch_object($sql)){ ?><option value="<? echo $row->fieldname;?>"><? echo $row->fieldname;?></option><? }?></select></td></tr><tr><td></td></tr></table> <script type="text/javascript"> /* ajax.Request */ function ajaxRequest(url,data,pagenumber) { var aj = new Ajax.Request( url, { method:'post', parameters:{"val": data,"pagenumber":pagenumber}, onComplete: getResponse } ); } /* ajax.Response */ function getResponse(oReq) { $('display').innerHTML = oReq.responseText; } </script> Quote Link to comment Share on other sites More sharing options...
zenag Posted October 30, 2008 Share Posted October 30, 2008 ajax.php <? $VALUE=$_POST['val']; $con=mysql_connect("localhost","root",""); mysql_select_db("db",$con); $total="select count(*) as count from table2 where fieldname='".$VALUE."'"; $totalcount=mysql_result(mysql_query($total),0); $perpage=2; $limitstart=$_POST['pagenumber'] * $perpage; $limitend=$perpage; $totalpage=ceil($totalcount/$perpage); $sql=mysql_query("select * from table2 where fieldname='".$VALUE."' LIMIT ".$limitstart.",".$limitend); ?> <table><? while($row=mysql_fetch_array($sql)) {?><tr><td><? echo $row["password"];?></td></tr><? } ?><tr><td><a href="javascript:ajaxRequest('ajax.php','<? echo $_POST['val']?>','<? echo $_POST['pagenumber']-1?>')">Previous</a></td><td>Page: <? echo $_POST['pagenumber']+1?>/<? echo $totalpage?></td><td><a href="javascript:ajaxRequest('ajax.php','<? echo $_POST['val']?>','<? echo $_POST['pagenumber']+1?>')">Next</a></td></tr></table> just download prorotype.js from google and paste it in ur directory Quote Link to comment Share on other sites More sharing options...
acctman Posted November 11, 2008 Author Share Posted November 11, 2008 I couldn't get that coding to work, do you have any other examples? pretty much what i'd like is a php query that with a limit of 5 set and the results are dumped into a div id=results and then everytime the user clicks next 5 more new results are added to the div id so its like a virtual ajax pagination without having actual pages Quote Link to comment Share on other sites More sharing options...
acctman Posted December 9, 2008 Author Share Posted December 9, 2008 any other examples of an ajax paginate? I've already tried the one on dynamicdrive and its more of a virtual paginate and not a true database result limit type paginate Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.