web 2.0

How to use PHP & Access (odbc) and Paging/Pagination

How to use PHP & Access (odbc) and Paging/Pagination This is tutorial  php developers how to using PHP get data from microsoft access database and display result of multiple pages to pagination.

ShotDev Focus:
- PHP & Microsoft Access  list data and pagination.

Example

php_access_pagination.php

  1. <html>  
  2. <head>  
  3. <title>ShotDev.Com Tutorial</title>  
  4. </head>  
  5. <body>  
  6. <?  
  7. $objConnect = odbc_connect("mydatabase","","");  
  8. $strSQL = "SELECT * FROM customer ORDER BY CustomerID ASC";  
  9. $objExec = odbc_exec($objConnect$strSQLor die ("Error Execute [".$strSQL."]");  
  10. $Num_Rows = 0;  
  11. while(odbc_fetch_row($objExec))$Num_Rows++; // Count Record  
  12.   
  13. $Per_Page = 2;   // Per Page  
  14.   
  15. $Page = $_GET["Page"];  
  16. if(!$_GET["Page"])  
  17. {  
  18. $Page=1;  
  19. }  
  20.   
  21. $Prev_Page = $Page-1;  
  22. $Next_Page = $Page+1;  
  23.   
  24. $Page_Start = (($Per_Page*$Page)-$Per_Page)+1;  
  25. if($Num_Rows<=$Per_Page)  
  26. {  
  27. $Num_Pages =1;  
  28. }  
  29. else if(($Num_Rows % $Per_Page)==0)  
  30. {  
  31. $Num_Pages =($Num_Rows/$Per_Page) ;  
  32. }  
  33. else  
  34. {  
  35. $Num_Pages =($Num_Rows/$Per_Page)+1;  
  36. $Num_Pages = (int)$Num_Pages;  
  37. }  
  38. $Page_End = $Per_Page * $Page;  
  39. if($Page_End > $Num_Rows)  
  40. {  
  41. $Page_End = $Num_Rows;  
  42. }  
  43. ?>  
  44.   
  45. <table width="600" border="1">  
  46. <tr>  
  47. <th width="91"> <div align="center">CustomerID </div></th>  
  48. <th width="98"> <div align="center">Name </div></th>  
  49. <th width="198"> <div align="center">Email </div></th>  
  50. <th width="97"> <div align="center">CountryCode </div></th>  
  51. <th width="59"> <div align="center">Budget </div></th>  
  52. <th width="71"> <div align="center">Used </div></th>  
  53. </tr>  
  54. <?  
  55. for($i=$Page_Start;$i<=$Page_End;$i++)  
  56. {  
  57. $objResult = odbc_fetch_array($objExec,$i);  
  58. ?>  
  59. <tr>  
  60. <td><div align="center"><?=$objResult["CustomerID"];?></div></td>  
  61. <td><?=$objResult["Name"];?></td>  
  62. <td><?=$objResult["Email"];?></td>  
  63. <td><div align="center"><?=$objResult["CountryCode"];?></div></td>  
  64. <td align="right"><?=$objResult["Budget"];?></td>  
  65. <td align="right"><?=$objResult["Used"];?></td>  
  66. </tr>  
  67. <?  
  68. }  
  69. ?>  
  70. </table>  
  71.   
  72. <br>  
  73. Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :  
  74. <?  
  75. if($Prev_Page)  
  76. {  
  77. echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> ";  
  78. }  
  79.   
  80. for($i=1; $i<=$Num_Pages$i++){  
  81. if($i != $Page)  
  82. {  
  83. echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";  
  84. }  
  85. else  
  86. {  
  87. echo "<b> $i </b>";  
  88. }  
  89. }  
  90. if($Page!=$Num_Pages)  
  91. {  
  92. echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a> ";  
  93. }  
  94.   
  95. odbc_close($objConnect);  
  96. ?>  
  97. </body>  
  98. </html>  

Create a php file and save to path root-path/myphp/

Run
http://localhost/myphp/php_access_pagination.php

Screenshot

PHP Microsoft Access (Paging/Pagination)
.
.
.

Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (1 votes, average: 1.00 out of 10)
Loading ... Loading ...

One Response to “How to use PHP & Access (odbc) and Paging/Pagination”

  1. 1carolina…

Leave a Reply

You must be logged in to post a comment.