Ten Days Society PHP on the 8th Day

xiaoxiao2021-03-06  37

Learning Purpose: To make a paging display key is to use the LIMIT in the SQL statement to qualify the recorded record from several to several. We need a variable that records the current page $ Page, you need a total record number $ NUM

For $ Page If we don't let it = 0, if you have <0, let it = 0, if you exceed the total number of pages, let him = total page number.

$ execc = "select count (*) from tablename";

$ resultC = mysql_query ($ execc);

$ rc = mysql_fetch_Array ($ Resultc);

$ Num = $ RSC [0];

This gives the total number of records

CEIL ($ NUM / 10)) If a page 10 records, this is the total number of pages.

So can write this

IF (EMPTY ($ _ get ['Page')))

{

$ PAGE = 0;

}

Else

{

$ Page = $ _ Get ['Page'];

IF ($ Page <0) $ Page = 0;

IF ($ page> = CEIL ($ NUM / 10)) $ Page = CEIL ($ Num / 10) -1; // Because Page starts from 0, -1

}

Such $ EXEC can write $ exec = "select * from tablename limited". ", 10";

// One page is 10 records

Finally, we need to do a few connections: firstpage

NextPage

转载请注明原文地址:https://www.9cbs.com/read-57581.html


New Post(0)