用PHP和SQL Sever實(shí)現(xiàn)分頁(yè)顯示
Jun 21, 2016 am 09:15 AM分頁(yè)|顯示
我們?cè)跒g覽網(wǎng)頁(yè)時(shí),經(jīng)常看到分頁(yè)顯示的頁(yè)面。如果想把大量數(shù)據(jù)提供給瀏覽者,分頁(yè)顯示是個(gè)非常實(shí)用的方法。在下面的文章中,我們將介紹如何用PHP和MS SQL Server實(shí)現(xiàn)對(duì)數(shù)據(jù)庫(kù)中紀(jì)錄的分頁(yè)顯示。
在本例中,我們用mssql_num_rows()函數(shù)得到當(dāng)前查詢的記錄數(shù),結(jié)合頁(yè)面大小SgPageSize,得到當(dāng)前記錄集要顯示的頁(yè)面數(shù),為分頁(yè)顯示打下了基礎(chǔ)。mssql_data_seek()函數(shù)是分頁(yè)顯示的關(guān)鍵函數(shù),該函數(shù)的第二個(gè)參數(shù)標(biāo)示當(dāng)前紀(jì)錄的偏移量,根據(jù)這個(gè)偏移量就可以找到要顯示的頁(yè)面。
分頁(yè)顯示源程序:
//為了便于理解和更快地應(yīng)用到工作中去,我們以MS SQL Server的NorthWind數(shù)據(jù)庫(kù)Customers表為例。
$gPageSize= 10; //每頁(yè)顯示的記錄數(shù)
$hostname = "localhost"; //MSSQL Server
$dbuser = "sa"; //用戶名
$dbpasswd = "1111111"; //密碼
//連接數(shù)據(jù)庫(kù)
$id = mssql_connect($hostname,$dbuser,$dbpasswd) or die("無(wú)法連接數(shù)據(jù)庫(kù)服務(wù)器!");
//選擇數(shù)據(jù)庫(kù),為了方便,這里以MSSQL Server的NorthWind數(shù)據(jù)庫(kù)為例
$db = mssql_select_db("northwind",$id) or die("無(wú)法連接數(shù)據(jù)庫(kù)!");
//以Customers表為例,構(gòu)建查詢字符串
$query = "select * from Customers";
//執(zhí)行查詢語(yǔ)句
$rresult = mssql_query($query) or die("無(wú)法執(zhí)行SQL:$query");
//$page變量標(biāo)示當(dāng)前顯示的頁(yè)
if(!isset($page)) $page=1;
if($page==0) $page=1;
//得到當(dāng)前查詢到的紀(jì)錄數(shù) $nNumRows
if(($nNumRows= mssql_num_rows($rresult))
{
echo "
沒(méi)有紀(jì)錄";
exit;
};
//得到最大頁(yè)碼數(shù)MaxPage
$MaxPage = (int)ceil($nNumRows/$gPageSize);
if((int)$page > $MaxPage)
$page=$maxPage;
?>
echo "第 $page 頁(yè),共 $MaxPage 頁(yè)";?> |
".mssql_field_name($rresult,$iCnt)." | " ;
".$arr[$nOffSet]." | ";
//首頁(yè)和上一頁(yè)的鏈接
if( $nNumRows>1 && $page>1)
{
$prevPage=$page-1;
echo " 首頁(yè) ";
echo " 上一頁(yè) ";
}
//下一頁(yè)和末頁(yè)的鏈接
if( $page>=1 && $page
{
$nextPage= $page+1;
echo " 下一頁(yè) ";
echo " 末頁(yè) ";
}
?>
把上述腳本程序進(jìn)行一些修改,你就可以建立自己的服務(wù)器端分頁(yè)顯示的腳本程序了。

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Methods for php to connect to mssql database include using PHP's MSSQL extension, using PDO, etc. Detailed introduction: 1. Use PHP's MSSQL extension method to ensure that PHP has the MSSQL extension installed. You can check whether the mssql extension is enabled in the PHP configuration file (php.ini); 2. Use the PDO method to ensure that PHP has the PDO extension installed. You can check whether the pdo_sqlsrv extension is enabled in the PHP configuration file (php.ini).

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

Ubuntu is a popular open source operating system commonly used to run servers. Installing PHP and configuring MSSQL connections on Ubuntu is one of the operations that many developers and system administrators often need to do. This article will provide readers with a detailed guide, including the steps to install PHP, set up Apache, install MSSQLServer, etc., and attach specific code examples. Step 1: Install PHP and related extensions First, we need to install PHP and related extensions to support PHP connections

Detailed steps for installing PHP to support MSSQL database in Ubuntu environment. When developing web applications, you often encounter situations where you need to connect to the Microsoft SQL Server (MSSQL) database. In the Ubuntu environment, to connect PHP to the MSSQL database, you need to install relevant software and configure appropriate settings. Next, we will introduce in detail the steps to install PHP to support MSSQL database in Ubuntu environment and provide specific code.

Implementing data paging and display optimization in Vue projects. In Vue projects, when a page needs to display a large amount of data, data paging and display optimization usually need to be performed to improve user experience. This article will introduce how to use Vue to implement data paging and display optimization. , and provide specific code examples. 1. Data paging Data paging refers to dividing a large amount of data into multiple pages according to certain rules and displaying them on the page. You can use the following steps to implement data paging in a Vue project: Define the data source. First, define a

Part 1: Initial Troubleshooting Steps Checking Apple’s System Status: Before delving into complex solutions, let’s start with the basics. The problem may not lie with your device; Apple's servers may be down. Visit Apple's System Status page to see if the AppStore is working properly. If there's a problem, all you can do is wait for Apple to fix it. Check your internet connection: Make sure you have a stable internet connection as the "Unable to connect to AppStore" issue can sometimes be attributed to a poor connection. Try switching between Wi-Fi and mobile data or resetting network settings (General > Reset > Reset Network Settings > Settings). Update your iOS version:

php提交表單通過(guò)后,彈出的對(duì)話框怎樣在當(dāng)前頁(yè)彈出php提交表單通過(guò)后,彈出的對(duì)話框怎樣在當(dāng)前頁(yè)彈出而不是在空白頁(yè)彈出?想實(shí)現(xiàn)這樣的效果:而不是空白頁(yè)彈出:------解決方案--------------------如果你的驗(yàn)證用PHP在后端,那么就用Ajax;僅供參考:HTML code
