⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 list.php

📁 是初学者学习和掌握php_mysql基本知识的理想的演示结合实践的教程
💻 PHP
字号:
<?php  echo $_SERVER['SCRIPT_NAME']."<BR>"; ?>
<?php
include_once("include/db_connection.php");

$initStartLimit = 0;
$limitPerPage = 10;

$startLimit = $_REQUEST['startLimit'];
$numberOfRows = $_REQUEST['rows'];
$sortBy = $_REQUEST['sortBy'];
$sortOrder = $_REQUEST['sortOrder'];

if ($startLimit=="")
{
		$startLimit = $initStartLimit;
}

if ($numberOfRows=="")
{
		$numberOfRows = $limitPerPage;
}

if ($sortOrder=="")
{
		$sortOrder  = "DESC";
}
if ($sortOrder == "DESC") { $newSortOrder = "ASC"; } else  { $newSortOrder = "DESC"; }
$limitQuery = " LIMIT ".$startLimit.",".$numberOfRows;
$nextStartLimit = $startLimit + $limitPerPage;
$previousStartLimit = $startLimit - $limitPerPage;

if ($sortBy!="")
{
		$orderByQuery = " ORDER BY ".$sortBy." ".$sortOrder;
}


$sql = "SELECT * FROM customers".$orderByQuery.$limitQuery;
echo $sql."<br>";
 mysql_query("SET NAMES 'GB2312'");
$result = MYSQL_QUERY($sql);
$numberOfRows = MYSQL_NUM_ROWS($result);



if ($numberOfRows==0) {  
?>
<br />
没有找到记录 !!

<?php
}
else if ($numberOfRows>0) {

	$i=0;
?>


<br>
<br><br>
<TABLE CELLSPACING="0" CELLPADDING="3" BORDER="0" WIDTH="100%">
	<TR>
		<TD>
			<a href="<?php echo $PHP_SELF; ?>?sortBy=customer_id&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
				<B>Customer_id</B>			</a></TD>
		<TD>
			<a href="<?php echo $PHP_SELF; ?>?sortBy=fname&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
				<B>Fname</B>			</a></TD>
		<TD>
			<a href="<?php echo $PHP_SELF; ?>?sortBy=lname&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
				<B>Lname</B>			</a></TD>
		<TD>
			<a href="<?php echo $PHP_SELF; ?>?sortBy=company&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
				<B>Company</B>			</a></TD>
		<TD>
			<a href="<?php echo $PHP_SELF; ?>?sortBy=title&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
				<B>Title</B>			</a></TD>
		<TD>
			<a href="<?php echo $PHP_SELF; ?>?sortBy=address1&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
				<B>Address1</B>			</a></TD>
		<TD>
			<a href="<?php echo $PHP_SELF; ?>?sortBy=address2&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
				<B>Address2</B>			</a></TD>
		<TD>
			<a href="<?php echo $PHP_SELF; ?>?sortBy=city&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
				<B>City</B>			</a></TD>
		<TD>
			<a href="<?php echo $PHP_SELF; ?>?sortBy=state_province&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
				<B>State_province</B>			</a></TD>
		<TD>
			<a href="<?php echo $PHP_SELF; ?>?sortBy=country&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
				<B>Country</B>			</a></TD>
		<TD>
			<a href="<?php echo $PHP_SELF; ?>?sortBy=postal_code&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
				<B>Postal_code</B>			</a></TD>
		<TD>
			<a href="<?php echo $PHP_SELF; ?>?sortBy=phone&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
				<B>Phone</B>			</a></TD>
		<TD>
			<a href="<?php echo $PHP_SELF; ?>?sortBy=fax&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
				<B>Fax</B>			</a></TD>
	</TR>
<?php
	while ($i<$numberOfRows)
	{

		if (($i%2)==0) { $bgColor = "#FFFFFF"; } else { $bgColor = "#C0C0C0"; }

	$thisCustomer_id = MYSQL_RESULT($result,$i,"customer_id");
	$thisFname = MYSQL_RESULT($result,$i,"fname");
	$thisLname = MYSQL_RESULT($result,$i,"lname");
	$thisCompany = MYSQL_RESULT($result,$i,"company");
	$thisAddress1 = MYSQL_RESULT($result,$i,"address1");
	$thisAddress2 = MYSQL_RESULT($result,$i,"address2");
	$thisCity = MYSQL_RESULT($result,$i,"city");
	$thisState_province = MYSQL_RESULT($result,$i,"state_province");
	$thisCountry = MYSQL_RESULT($result,$i,"country");
	$thisPostal_code = MYSQL_RESULT($result,$i,"postal_code");
	$thisPhone = MYSQL_RESULT($result,$i,"phone");
	$thisFax = MYSQL_RESULT($result,$i,"fax");

?>
	<TR BGCOLOR="<?php echo $bgColor; ?>">
		<TD nowrap><?php echo $thisCustomer_id; ?></TD>
		<TD nowrap><?php echo $thisFname; ?></TD>
		<TD nowrap><?php echo $thisLname; ?></TD>
		<TD nowrap><?php echo $thisCompany; ?></TD>
		<TD nowrap><?php echo $thisAddress1; ?></TD>
		<TD nowrap><?php echo $thisAddress2; ?></TD>
		<TD nowrap><?php echo $thisCity; ?></TD>
		<TD nowrap><?php echo $thisState_province; ?></TD>
		<TD nowrap><?php echo $thisCountry; ?></TD>
		<TD nowrap><?php echo $thisPostal_code; ?></TD>
		<TD nowrap><?php echo $thisPhone; ?></TD>
		<TD nowrap><?php echo $thisFax; ?></TD>
	<TD><a href="edit.php?customer_idField=<?php echo $thisCustomer_id; ?>">Edit</a></TD>
	<TD><a href="confirm_delete.php?customer_idField=<?php echo $thisCustomer_id; ?>">Delete</a></TD>
	</TR>
<?php
		$i++;

	} 
?>
</TABLE>


<p>&nbsp;</p>
<table width="550" border="0" cellpadding="2" cellspacing="2" bgcolor="#000000">
  <tr>
    <td><table width="550"  border="0" cellpadding="1" cellspacing="0" bgcolor="#FFFFFF">
      <?php
	$i = 0;
	while ($i<$numberOfRows)
	{

		if (($i%2)==0) { $bgColor = "#FFFFFF"; } else { $bgColor = "#CCCCCC"; }

	$thisCustomer_id = MYSQL_RESULT($result,$i,"customer_id");
	$thisFname = MYSQL_RESULT($result,$i,"fname");
	$thisLname = MYSQL_RESULT($result,$i,"lname");
	$thisCompany = MYSQL_RESULT($result,$i,"company");
	$thisAddress1 = MYSQL_RESULT($result,$i,"address1");
	$thisAddress2 = MYSQL_RESULT($result,$i,"address2");
	$thisCity = MYSQL_RESULT($result,$i,"city");
	$thisState_province = MYSQL_RESULT($result,$i,"state_province");
	$thisCountry = MYSQL_RESULT($result,$i,"country");
	$thisPostal_code = MYSQL_RESULT($result,$i,"postal_code");
	$thisPhone = MYSQL_RESULT($result,$i,"phone");
	$thisFax = MYSQL_RESULT($result,$i,"fax");

?>
      <tr>
        <td width="12" bgcolor="<?php echo $bgColor ?>">&nbsp;</td>
        <td width="399" bgcolor="<?php echo $bgColor ?>"><span style="font-weight: bold; font-size: 15px;"><?php echo $thisCustomer_id; ?> -</span> <span style="color: #000099; font-weight: bold;"><?php echo $thisFname." ".$thisLname; ?> <br>
              <span style="color: #000099; font-weight: bold;"><?php echo $thisCompany; ?></span></span><br>
              <?php echo $thisAddress1; ?> <?php echo $thisAddress2; ?>  <br>
              <?php echo $thisCity; ?>, <?php echo $thisState_province; ?><br>
              <?php echo $thisCountry; ?> <?php echo $thisPostal_code; ?><br>
      Phone: <?php echo $thisPhone; ?> Fax: <?php echo $thisFax; ?><br></td>
        <td width="111" valign="top" bgcolor="<?php echo $bgColor ?>"><a href="edit.php?customer_idField=<?php echo $thisCustomer_id; ?>"><br>
          修改</a><br>
            <a href="confirm_delete.php?customer_idField=<?php echo $thisCustomer_id; ?>">删除</a></td>
      </tr>
      <?php
		$i++;

	} 
?>
    </table></td>
  </tr>
</table>
<p>  <?php
if ($_REQUEST['startLimit'] != "")
{
?>

  <a href="<?php echo  $_SERVER['PHP_SELF']; ?>?startLimit=<?php echo $previousStartLimit; ?>&limitPerPage=<?php echo $limitPerPage; ?>&sortBy=<?php echo $sortBy; ?>&sortOrder=<?php echo $sortOrder; ?>">Previous <?php echo $limitPerPage; ?> Results</a>....
  <?php } ?>
  <?php
if ($numberOfRows == $limitPerPage)
{
?>
  <a href="<?php echo $_SERVER['PHP_SELF']; ?>?startLimit=<?php echo $nextStartLimit; ?>&limitPerPage=<?php echo $limitPerPage; ?>&sortBy=<?php echo $sortBy; ?>&sortOrder=<?php echo $sortOrder; ?>">Next <?php echo $limitPerPage; ?> Results</a>
  <?php } ?>

  <br>
  <br>
  <?php
} 
 ?>
</p>
<ul>
    <li><div align="left"><a href="enter_new.php">&#28155;&#21152;&#26032;&#32426;&#24405;</a></div>
    </li>
              <li>
                <div align="left"><a href="list.php">&#25152;&#26377;&#35760;&#24405;&#21015;&#34920;</a></div>
    </li>
              <li>
                <div align="left"><a href="search_form.php">&#25628;&#32034;&#35760;&#24405;</a></div>
    </li>
</ul>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p></p>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -