web 2.0

How to use PHP & SQL Server (mssql) Display Multiple Column and Paging/Pagination

How to use PHP & SQL Server (mssql) Display Multiple Column and Paging/Pagination Learn / tutorial php programming how to using  PHP list data from SQL Server database and display all result of multiple column and showing data in pagination.

ShotDev Focus:
- PHP & SQL Server list data , multiple column and pagination

Example

php_sqlserver_column_pagination.php

  1. <html>  
  2. <head>  
  3. <title>ShotDev.Com Tutorial</title>  
  4. </head>  
  5. <body>  
  6. <?  
  7. $objConnect = mssql_connect("localhost","sa","");  
  8. $objDB = mssql_select_db("mydatabase");  
  9. $strSQL = "SELECT * FROM gallery";  
  10. $objQuery = mssql_query($strSQLor die ("Error Query [".$strSQL."]");  
  11. $Num_Rows = mssql_num_rows($objQuery);  
  12.   
  13. $Per_Page = 4;   // 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);  
  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. echo"<table border=\"0\"  cellspacing=\"1\" cellpadding=\"1\"><tr>";  
  45. $intRows = 0;  
  46. for($i=$Page_Start;$i<$Page_End;$i++)  
  47. {  
  48. echo "<td>";  
  49. $intRows++;  
  50. ?>  
  51. <center>  
  52. <img src="shotdev/<?=mssql_result($objQuery,$i,"Picture");?>"><br>  
  53. <?=mssql_result($objQuery,$i,"GalleryName");?>  
  54. <br>  
  55. </center>  
  56. <?  
  57. echo"</td>";  
  58. if(($intRows)%2==0)  
  59. {  
  60. echo"</tr>";  
  61. }  
  62. }  
  63. echo"</tr></table>";  
  64. ?>  
  65.   
  66. <br>  
  67. Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :  
  68. <?  
  69. if($Prev_Page)  
  70. {  
  71. echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> ";  
  72. }  
  73.   
  74. for($i=1; $i<=$Num_Pages$i++){  
  75. if($i != $Page)  
  76. {  
  77. echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";  
  78. }  
  79. else  
  80. {  
  81. echo "<b> $i </b>";  
  82. }  
  83. }  
  84. if($Page!=$Num_Pages)  
  85. {  
  86. echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a> ";  
  87. }  
  88. mssql_close($objConnect);  
  89. ?>  
  90. </body>  
  91. </html>  
  92. <?  
  93. mssql_close($objConnect);  
  94. ?>  

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

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

Screenshot

PHP & SQL Server (mssql) Display Multiple Column and 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 ...

Leave a Reply

You must be logged in to post a comment.