search
HomeBackend DevelopmentPHP TutorialPHP reads mysql database data and implements paging example code_PHP tutorial

PHP reads mysql database data and implements paging example code as follows:

  1. //Connect to the database
  2. $db =mysql_connect("localhost","root","root");
  3. mysql_select_db("gaoge",$db);
  4. //Set the number of records displayed on each page
  5. $pagesize=3;
  6. //Get the total number of records and calculate the total number of pages
  7. $res=mysql_query("select count(*) from image " ,$db);
  8. $myrow = mysql_fetch_array($res);
  9. //$myrow[o] is the sum of the total number of records in the database
  10. $numrows=$myrow[0];
  11. //echo "total num is:";
  12. //echo $numrows;
  13. // echo
    ;
  14. //Calculate the total number of pages
  15. $pages=intval($numrows/$pagesize);
  16. if ($numrows%$pagesize )
  17. $pages ;
  18. // echo "total pages is:";
  19. //echo $pages;
  20. //echo
    ;
  21. //Determine whether the page number is set or not, if not, it is defined as the home page
  22. if (isset($_GET[page])){
  23. //echo "page exist";
  24. $page = $_GET[page];
  25. //echo "enter if ";
  26. }
  27. else{
  28. //echo "page not exist";
  29. $page = 1;
  30. }
  31. //echo "page is:" ;
  32. // echo $page;
  33. // echo
    ;
  34. //Calculate record bias Offset
  35. $offset=$pagesize*($page-1);
  36. // echo "offset is:" ;
  37. echo $offset;
  38. //Get records
  39. $res=mysql_query("select * from image order by id desc limit $offset,$pagesize" ,$db);
  40. //Loop display records
  41. if ($myrow = mysql_fetch_array($res))
  42. {
  43. $i=0;
  44. ?>
  45. < ;table cellspacing=0 bordercolordark=#FFFFFF width="95%" bordercolorlight=#000000 border=1 align="center" cellpadding="2">
  46.   ID
  47.   Picture name
  48.   Uploader name
  49. Upload time
  50. Picture effect
  51. do {
  52. $i ;
  53. ?>
  54. PHP reads mysql database data and implements paging example code_PHP tutorial
  55. }
  56. while ($myrow = mysql_fetch_array ($res));
  57. echo "" ;
  58. }
  59. //Display the total number of pages
  60. echo "
    There are ".$pages." pages (".$page."/".$pages.")
    ";
  61. //Display the number of pages
  62. for ($i=1;$i
  63. echo "< ;a href=pages.php?page=".$i.">Page ".$i ." ";
  64. //echo "page is:";
  65. //echo "$page";
  66. // echo "
    ";
  67. //Display the page number
  68. echo "
    ";
  69. //Calculate the page values ​​of the first page, previous page, next page and last page
  70. $ first=1;
  71. $prev=$page-1;
  72. $next=$page 1;
  73. $last=$pages;
  74. echo "Homepage ";
  75. //echo "page is:";
  76. //echo "$page";
  77. echo "Previous page ";
  78. echo "Next page ";
  79. echo "Last page ";
  80. echo "";
  81. echo "
";
  • ?>
  • www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486122.htmlTechArticlePHP reads mysql database data and implements paging example code as follows: ?php //Connect to the database $db=mysql_connect( "localhost","root","root"); mysql_select_db("gaoge",$db); //Set each page to display...
    Statement
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    PHP Performance Tuning for High Traffic WebsitesPHP Performance Tuning for High Traffic WebsitesMay 14, 2025 am 12:13 AM

    ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

    Dependency Injection in PHP: Code Examples for BeginnersDependency Injection in PHP: Code Examples for BeginnersMay 14, 2025 am 12:08 AM

    You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

    PHP Performance: is it possible to optimize the application?PHP Performance: is it possible to optimize the application?May 14, 2025 am 12:04 AM

    Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

    PHP Performance Optimization: The Ultimate GuidePHP Performance Optimization: The Ultimate GuideMay 14, 2025 am 12:02 AM

    ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

    PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

    APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

    Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

    Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

    PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

    PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

    PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

    PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

    See all articles

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Article

    Hot Tools

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    WebStorm Mac version

    WebStorm Mac version

    Useful JavaScript development tools

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    SublimeText3 Linux new version

    SublimeText3 Linux new version

    SublimeText3 Linux latest version

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools