Ask Php+sqlserver to turn the effect, how to deal with

Source: Internet
Author: User
Seeking the Php+sqlserver effect of the page



<title>Pagination instance</title>




Error_reporting (7);
Initialize page link parameters
$page =$_get["page"]+0; Think about whether this is a cast to an integer or a method?
$page = $page <=0? 1: $page; Avoid cases where $_get["page" is negative and 0

Paging size
$page _size=10;

$serverName = "(local)"; Database server address
$uid = "sa"; Database user Name
$pwd = "Ulptfstx"; Database Password
$connectionInfo = Array ("UID" = = $uid, "PWD" + = $pwd, "Database" = "MSD");
$conn = Sqlsrv_connect ($serverName, $connectionInfo);
if ($conn = = False) {
echo "Connection failed! ";
Die (Print_r (Sqlsrv_errors (), true));
}

Calculate Total rows
$total _records=sqlsrv_num_rows (sqlsrv_query ("Select MB001 from INVMB");

Total pages
$total _page=ceil ($total _records/$page _size); into a method to take the whole, to avoid the last page of dissatisfaction $page_size,

$page = $page > $total _page? $total _page: $page; Avoid $_get["page"] greater than total pages

Page link Start
$page _link= "";
if ($total _page>1)
{
$page _link= "Altogether {$total _page} page";
$page _link.= "The current {$page} page";
$page _link.= "Home";

if ($page >1) {
When the page number is greater than 1, the previous page link is displayed
$pre _page= $page-1;
$page _link.= "<<";
}
Flip List
for ($i =1; $i <= $total _page; $i + +)
{
if ($i = = $page)
{
Highlight current Page page number
$page _link.= "$i";
}
Else
{
$page _link.= "$i";
}
}
Page is less than the total number of pages to display the next page link
$next _page= $page +1;
if ($next _page< $total _page)
{
$page _link.= ">>";
}
$page _link.= "last page";
}
Output record

$offset = ($page-1) * $page _size;
$query =sqlsrv_query ("select * from INVMB limit $offset, $page _size") or Die (Sqlsrv_error ());
echo "
      ";
      while ($rs =sqlsrv_fetch_array ($query))
      {
      echo "
    • {$rs ["0"]}-{$rs ["1"]}
    • ";
      }
      echo "
        ";
        echo "$page _link";

        ?>


This code comes from http://topic.csdn.net/u/20120117/11/c2618d08-b88c-4586-8b00-f1938f5c7792.html
How to change it to connect to SQL Server, now run the following error:

Warning:sqlsrv_query () expects at least 2 parameters, 1 given in D:\Apache server\apache\htdocs\bbs\demo.php on line 33
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.