simzam Posted December 17, 2010 Share Posted December 17, 2010 Guys i badly need need to add paging in this . 20 records per page how to accomplish ? <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); $http = 'myurl.com/other.php?like=' ; $conn=odbc_connect('apple','',''); if (!$conn) {exit("Connection Failed: " . $conn);} $sql="SELECT * FROM mytable "; $rs=odbc_exec($conn,$sql); if (!$rs) {exit("Error in SQL");} echo "<table border= 1><tr>"; echo "<th>ID</th>"; echo "<th>Like</th>"; echo "<th>title</th></tr>"; while (odbc_fetch_row($rs)) { $ids=odbc_result($rs,"ID"); // $links=odbc_result($rs,"links"); $title=odbc_result($rs,"title"); echo "<tr><td>$ids</td>"; echo "<td><fb:like href=\"{$http}{$ids}\" layout=\"button_count\" show_faces=\"false\" width=\"100\" font=\"tahoma\" colorscheme=\"dark\"></fb:like> </td>"; echo "<td>$title</td></tr>"; } echo "</table>"; odbc_close($conn); ?> Quote Link to comment Share on other sites More sharing options...
litebearer Posted December 17, 2010 Share Posted December 17, 2010 I use this it works great http://phpsense.com/php/php-pagination-script.html Quote Link to comment Share on other sites More sharing options...
simzam Posted December 17, 2010 Author Share Posted December 17, 2010 gr8 tutorial but I'm not that clever this link use paging for Mysql and i want for ms access like above code kindly fit for me Quote Link to comment Share on other sites More sharing options...
shlumph Posted December 17, 2010 Share Posted December 17, 2010 You're gonna have to limit and offset your query. Your limit will be the number of items you want displayed per page. Each page will have a different offset. Quote Link to comment Share on other sites More sharing options...
simzam Posted December 17, 2010 Author Share Posted December 17, 2010 I tried but fails ! <?php //Include the PS_Pagination class include('ps_pagination.php'); //Connect to mysql db $conn = odbc_connect('apple', '', ''); $sql = 'select title from mytable'; //Create a PS_Pagination object $pager = new PS_Pagination($conn, $sql, 8, 3, 'param1=valu1¶m2=value2'); //The paginate() function returns a mysql //result set for the current page $rs = $pager->paginate(); //Loop through the result set while($row = odbc_fetch_row($rs)) { echo $row['title']; } //Display the navigation echo $pager->renderFullNav(); ?> Quote Link to comment Share on other sites More sharing options...
simzam Posted December 18, 2010 Author Share Posted December 18, 2010 no 1 knows ? kindly help me to achieve paging my data Quote Link to comment Share on other sites More sharing options...
simzam Posted December 18, 2010 Author Share Posted December 18, 2010 I'm close to finishing The problem I am having is when the user clicks on one of the navigation links (i.e. First, Next, Prev, Last), the records do not display -- it remains on the first 10 records. However, the page number URL variable do change appropriately. <?php // how many rows to show per page $introwsPerPage = 10; // by default show first page $intpageNum = 1; // if $_GET['intpage'] defined, use it as page number if(isset($_GET['intpage'])) { $intpageNum = $_GET['intpage']; } // counting the offset $offset = ($intpageNum - 1) * $introwsPerPage; //connect to a DSN ('Name of DSN', 'UserName', 'Password') //odbc_connect: Connect to a datasource $conn = odbc_connect('apple','','') or die('Unable to connect to database'); //the SQL statement that will query the database $qryCandidate = "SELECT TOP 10 id, title FROM mytable"; //perform the query //odbc_exec: Prepare and execute a SQL statement $qryresult=odbc_exec($conn, $qryCandidate); //retrieve the data from the database //odbc_fetch_row: Fetch a row while(@odbc_fetch_row($qryresult)) { //odbc_result: Get result data $txtLastName = odbc_result($qryresult, "id"); $txtFirstName = odbc_result($qryresult, "title"); //Display Results echo ("<tr bgcolor=\"$color\">"); echo ("<td height=\"10\">$txtLastName, $txtFirstName</td>"); echo ("<td><a href=\"admin.php?Candidate=$Candidate \"><div align=\"center\">[Edit]</div></a></td>"); echo ("</tr>"); } // how many rows we have in database $querycount = "SELECT COUNT(id) AS intnumrows FROM "; $result = odbc_exec($conn, $querycount); $row = odbc_fetch_array($result); $intnumrows = $row['intnumrows']; // how many pages we have when using paging? $intmaxPage = ceil($intnumrows/$introwsPerPage); // print the link to access each page $self = $_SERVER['PHP_SELF']; $nav = ''; for($intpage = 1; $intpage <= $intmaxPage; $intpage++) { if ($page == $intpageNum) { $nav .= " $intpage "; // no need to create a link to current page } else { $nav .= " <a href=\"$self?intpage=$intpage\">$page</a> "; } } // creating previous and next link // plus the link to go straight to // the first and last page if ($intpageNum > 1) { $intpage = $intpageNum - 1; $prev = " <a href=\"$self?intpage=$intpage\">[Prev]</a> "; $first = " <a href=\"$self?intpage=1\">[First Page]</a> "; } else { $prev = ' '; // we're on page one, don't print previous link $first = ' '; // nor the first page link } if ($intpageNum < $intmaxPage) { $intpage = $intpageNum + 1; $next = " <a href=\"$self?intpage=$intpage\">[Next]</a> "; $last = " <a href=\"$self?intpage=$intmaxPage\">[Last Page]</a> "; } else { $next = ' '; // we're on the last page, don't print next link $last = ' '; // nor the last page link } //Display Navigation echo ("<tr>"); echo ("<td colspan=\"5\" align=\"center\">"); echo ("<br/><br/>$first $prev $next $last"); echo ("<br/><br/>"); echo ("<center>"); echo ("<A HREF=\"page1.php\">Return to HomePage</a>"); echo ("</center>"); echo ("</td>"); echo ("</tr>"); echo ("</table>"); //disconnect the db odbc_close($conn); ?> Quote Link to comment Share on other sites More sharing options...
shlumph Posted December 20, 2010 Share Posted December 20, 2010 You need to modify your select query: <?php $qryCandidate = "SELECT id, title FROM mytable LIMIT {$offset}, {$introwsPerPage}"; Quote Link to comment Share on other sites More sharing options...
simzam Posted December 20, 2010 Author Share Posted December 20, 2010 Unfortunately, there isn't an offset clause ms - access Quote Link to comment Share on other sites More sharing options...
shlumph Posted December 20, 2010 Share Posted December 20, 2010 Ohh, you're using access. That I'm not familiar with, sorry. 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.