search

  1. @session_start();
  2. require_once("smarty.php");//Load smarty template class
  3. require_once("adodb/adodb.inc.php");/ /Load adodb database
  4. //Connect to database

  5. $dbhost = 'localhost'; // Database server
  6. $dbuser = 'root'; // Database user name
  7. $dbpwd= 'root' ; // Database password
  8. $dbname='hejia'; //Database name
  9. $conn = NewAdoConnection('mysql'); // Create connection object

  10. $conn->Connect( $dbhost, $dbuser, $dbpwd, $dbname); //Connect to the database
  11. $conn->Query("Set Names 'gb2312'"); //Sourced from mysql_query("SET NAMES GBK");
  12. date_default_timezone_set( PRC); //The solution for PHP to obtain the time difference of 8 hours, you can also modify the date.timezone in php.ini to PRC
  13. ?>
Copy the code

Homepage index.php:

  1. require_once("const.php");
  2. $sql1="select id,hits,title,add_date from oa_art order by id desc"; //SQL statement
  3. $pageSize=4; //Set the number of records per page
  4. $sql=$sql1." limit ".($pageSize * ((empty($_REQUEST['page']) ? 1 : $_REQUEST['page']) -1)).", ".$pageSize;
  5. $news_array=$conn->getall($sql);
  6. $news_array1=$conn->getall($sql1);
  7. $page_url="index.php "; //Page url address
  8. $totalnumber=count($news_array1); //Get the total number of records
  9. $midPage=5; //Number of digital navigation links
  10. page();// Call the paging function
  11. for ($i = 0; $i $smarty-> assign("page_option",$page_option);

  12. $smarty->assign("news_data",$news_array);

  13. $smarty->assign("mytitle","Corporate website Home page");
  14. $smarty->display("tpl.htm",$page);
  15. ?>
Copy code

Paging function:

  1. function page()

  2. {
  3. global $smarty,$start,$page_url,$pageSize,$midPage,$totalnumber;
  4. $total = $totalnumber ; / /Get the total number of records
  5. $totalPage = ceil($total/$pageSize); //Get the total number of pages
  6. $currentPage=@$_REQUEST['page']+0; //Current page
  7. if(!is_numeric($ currentPage) || $currentPage $totalPage)
  8. $currentPage=1; //Initialize the current page
  9. $url = preg_replace(array("!(([& ]|^)(page)[=]?([^&]+)?)|((([&]){2,})|(^[&])|([&]$))!" ,),array(""),$_SERVER["QUERY_STRING"]); // Set the address and replace it with regular
  10. $url.=($url?"&":"").'page'; // Append
  11. $start = ($currentPage-1)*$pageSize;
  12. $back = $currentPage > 1?"n":"";
  13. $next = $currentPage >>n":"";
  14. $first = $ currentPage > 1?"Homepagen":"";
  15. $last = $currentPage Last pagen":"";
  16. // Navigation link

  17. $midPages = '';
  18. $num = $currentPage-floor($midPage/2);
  19. if($num > 0)
  20. {
  21. if(($totalPage-$num) {
  22. $tmp = $totalPage - $midPage;
  23. $num = $tmp }
  24. }else $num = 1;
  25. for($i=1; $i< ;=$midPage;$i++,$num++)
  26. {
  27. if($num > $totalPage) break;
  28. $midPages .= ($num == $currentPage) ? '['.$num.'] ' : "".$num." ";
  29. }
  30. $ smarty->assign("page_total",$total); // Total
  31. $smarty->assign("page_currentPage",$currentPage); // Current page number
  32. $smarty->assign("page_totalPage",$ totalPage); // Total number of pages
  33. $smarty->assign("page_back",$back); // Previous page
  34. $smarty->assign("page_next",$next); // Next page
  35. $smarty->assign("page_first",$first); // Homepage
  36. $smarty->assign("page_last",$last); // Last page
  37. $smarty->assign("page_midPages" ,$midPages); // Middle page
  38. $smarty->assign("page_url",$page_url); // Current page address
  39. }
  40. ?>
Copy code

模板页 tpl.htm:

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
Explain how load balancing affects session management and how to address it.Explain how load balancing affects session management and how to address it.Apr 29, 2025 am 12:42 AM

Load balancing affects session management, but can be resolved with session replication, session stickiness, and centralized session storage. 1. Session Replication Copy session data between servers. 2. Session stickiness directs user requests to the same server. 3. Centralized session storage uses independent servers such as Redis to store session data to ensure data sharing.

Explain the concept of session locking.Explain the concept of session locking.Apr 29, 2025 am 12:39 AM

Sessionlockingisatechniqueusedtoensureauser'ssessionremainsexclusivetooneuseratatime.Itiscrucialforpreventingdatacorruptionandsecuritybreachesinmulti-userapplications.Sessionlockingisimplementedusingserver-sidelockingmechanisms,suchasReentrantLockinJ

Are there any alternatives to PHP sessions?Are there any alternatives to PHP sessions?Apr 29, 2025 am 12:36 AM

Alternatives to PHP sessions include Cookies, Token-based Authentication, Database-based Sessions, and Redis/Memcached. 1.Cookies manage sessions by storing data on the client, which is simple but low in security. 2.Token-based Authentication uses tokens to verify users, which is highly secure but requires additional logic. 3.Database-basedSessions stores data in the database, which has good scalability but may affect performance. 4. Redis/Memcached uses distributed cache to improve performance and scalability, but requires additional matching

Define the term 'session hijacking' in the context of PHP.Define the term 'session hijacking' in the context of PHP.Apr 29, 2025 am 12:33 AM

Sessionhijacking refers to an attacker impersonating a user by obtaining the user's sessionID. Prevention methods include: 1) encrypting communication using HTTPS; 2) verifying the source of the sessionID; 3) using a secure sessionID generation algorithm; 4) regularly updating the sessionID.

What is the full form of PHP?What is the full form of PHP?Apr 28, 2025 pm 04:58 PM

The article discusses PHP, detailing its full form, main uses in web development, comparison with Python and Java, and its ease of learning for beginners.

How does PHP handle form data?How does PHP handle form data?Apr 28, 2025 pm 04:57 PM

PHP handles form data using $\_POST and $\_GET superglobals, with security ensured through validation, sanitization, and secure database interactions.

What is the difference between PHP and ASP.NET?What is the difference between PHP and ASP.NET?Apr 28, 2025 pm 04:56 PM

The article compares PHP and ASP.NET, focusing on their suitability for large-scale web applications, performance differences, and security features. Both are viable for large projects, but PHP is open-source and platform-independent, while ASP.NET,

Is PHP a case-sensitive language?Is PHP a case-sensitive language?Apr 28, 2025 pm 04:55 PM

PHP's case sensitivity varies: functions are insensitive, while variables and classes are sensitive. Best practices include consistent naming and using case-insensitive functions for comparisons.

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 Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment