Write yourself a page showing the class

Source: Internet
Author: User
Paging | Show class.php:
?
/*
-----------------------------------------------------------------------------------------------
Name: Turnpage
Function: Pagination display
member functions:
Entrance (): The entry of the class, parameter is the parameter of all member functions
Selectdata ($connection, $query): A function that selects data, returns an array
ShowData ($array, $i, $j): A function that displays the values of each field, returns a value
Maketable ($array, $intPageBegin, $intPageEnd): The function that generates the table, generates the corresponding table according to the number of fields to be displayed, the parameters are: array, the information ordinal of the beginning of each page, the information ordinal of the end of each page
Makelink ($parameter =null): The link to the page is displayed, and the parameters are optional
GetFileName (): Remove the name of the current execution file, return the file name

The relationship between functions:
-----------------------------------------------------------------------------------------------
*/
Class Turnpage
{
var $strArray;
var $cols;
var $rows;
var $strFieldName;
var $intPageBegin;
var $intPageEnd;

function entrance ($connection, $query)
{
$myArray = $this->selectdata ($connection, $query);

$this->getfilename ();

$this->makelink ($parameter =null);


$this->maketable ($myArray, $this->intpagebegin, $this->intpageend);

}

function Selectdata ($connection, $query)
{
$result = @mysql_query ($query, $connection) or die ("Unable to select the data!");

$intFieldsNum =mysql_num_fields ($result);

for ($a =0; $a < $intFieldsNum; $a + +)//Get the names of each field selected
{
$this->strfieldname[$a]=mysql_field_name ($result, $a);
}

$this->cols= $intFieldsNum;

$count = 0;

while ($rows =mysql_fetch_row ($result))
{
for ($i =0; $i < $intFieldsNum; $i + +)
{
$data [$count] [$i]=trim ($rows [$i]);
}
$count + +;
}
$this->rows=count ($data);
$this->strarray= $data;
return $this->strarray;
}

function ShowData ($array, $i, $j)
{
return $array [$i] [$j];
}

function maketable ($array, $intPageBegin, $intPageEnd)
{
echo "<table border=0 width=100% align=center cellspacing=1 cellpadding=5 bgcolor= #004080 >";
echo "<tr height=20 bgcolor= #0080C0 align=center>";
For ($m =0 $m < $this->cols; $m + +)
{
echo "<td><font color=white>". $this->strfieldname[$m]. " </font></td> ";
}
echo "</tr>";

for ($i = $intPageBegin; $i < $intPageEnd; $i + +)
{
if ($i%2==0)
{
$bgColor = "#D2F0FF";
}
Else
{
$bgColor = "#ffffff";
}
echo "<tr bgcolor=". $bgColor. "Align=center onmouseover=this.style.backgroundcolor=@# #FFCC66 @# onmouseout= this.style.backgroundcolor=@#@# onclick=this.style.backgroundcolor=@# #cccccc @#> ";
For ($j =0 $j < $this->cols; $j + +)
{
echo "<td>" $this->showdata ($array, $i, $j). " </td> ";
}
echo "</tr>";
}
echo "</table>";
}

function GetFileName ()
{
$strPath =$_server[@ #PHP_SELF @#];
$strFileName =trim (substr ($strPath, (Strrpos ($strPath, "/") +1));
return $strFileName;
}

function Makelink ($parameter =null)
{
if ($parameter ==null)
{
$strParam =null;
}
Else
{
$strParam = $parameter;
}

if ($_get["Intpage"]==null)
{
$intPage = 1;
}
Else
{
$intPage =trim ($_get[@ #intPage @#]);
}

$intPerPage = 10;

$total = $this->rows;

$strFile = $this->getfilename ();

$intPageBegin = $intPerPage * $intPage-$intPerPage;

$this->intpagebegin= $intPageBegin;



if ($intPage * $intPerPage < $total)
{
$intPageEnd = $intPageBegin + $intPerPage;
}
Else
{
$intPageEnd = $total;
}

$this->intpageend= $intPageEnd;

echo "<table width=100% border=0><tr><td width=60% align=left> Total Information:". $this->rows. " &LT;/TD&GT;&LT;TD width=20%> ";
if ($intPage >1)
{
echo "<a href=". $strFile. "? Intpage= ". ($intPage-1). " > Prev </a> ";
}
echo "</td><td width=20%>";
if ($intPage * $intPerPage < $total)
{
echo "<a href=". $strFile. "? Intpage= ". ($intPage + 1). " > next page </a> ";
}
echo "</td></tr></table>";

}

}
?>
test.php:
?
Include (".. /common/connection.php "); Connecting to database operations
Include (".. /common/class.php "); Include the above file in the recent

$query = "SELECT * from Uphoto ORDER by intuid ASC";

$test =new Turnpage;

$test->entrance ($connection, $query);

?>


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.