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

📄 search.php

📁 是初学者学习和掌握php_mysql基本知识的理想的演示结合实践的教程
💻 PHP
字号:
<?php  echo $_SERVER['SCRIPT_NAME']."<BR>"; ?>
<?php
include_once("include/db_connection.php");
mysql_query("SET NAMES 'GB2312'");
function highlightSearchTerms($fullText, $searchTerm, $bgcolor="#FFFF99")
{
	if (empty($searchTerm))
	{
		return $fullText;
	}
	else
	{
		$start_tag = "<span style=\"background-color: $bgcolor\">";
		$end_tag = "</span>";
		$highlighted_results = $start_tag . $searchTerm . $end_tag;
		return eregi_replace($searchTerm, $highlighted_results, $fullText);
	}
}

?>
<?php
$thisKeyword = $_REQUEST['keyword'];
?>
<?php

$newSortOrder = $_REQUEST['sortBy'];
if ($newSortOrder == "") $newSortOrder = "customer_id";

$sqlQuery = "SELECT *  FROM customers WHERE customer_id like '%$thisKeyword%'  OR fname like '%$thisKeyword%'  
		OR lname like '%$thisKeyword%'  OR company like '%$thisKeyword%'  
		OR address1 like '%$thisKeyword%'  OR address2 like '%$thisKeyword%'
	  	  OR city like '%$thisKeyword%'  OR state_province like '%$thisKeyword%'
		OR country like '%$thisKeyword%'  OR postal_code like '%$thisKeyword%'  OR phone like '%$thisKeyword%'
		OR fax like '%$thisKeyword%'";
		// ORDER BY $newSortOrder ";
		
		echo $sqlQuery;
		
$result = MYSQL_QUERY($sqlQuery);
$numberOfRows = MYSQL_NUM_ROWS($result);

?>
<?php
if ($numberOfRows==0) {  
?>

 Sorry. No records found !!

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

	$i=0;
?>
<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=mname&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
				<B>Mname</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=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=address3&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
				<B>Address3</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
$highlightColor = "#FFFF99"; 

	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");
	$thisCustomer_id = highlightSearchTerms($thisCustomer_id, $thisKeyword, $highlightColor); 
	$thisFname = highlightSearchTerms($thisFname, $thisKeyword, $highlightColor); 
	$thisLname = highlightSearchTerms($thisLname, $thisKeyword, $highlightColor); 
	$thisCompany = highlightSearchTerms($thisCompany, $thisKeyword, $highlightColor); 
	$thisAddress1 = highlightSearchTerms($thisAddress1, $thisKeyword, $highlightColor); 
	$thisAddress2 = highlightSearchTerms($thisAddress2, $thisKeyword, $highlightColor); 
	$thisCity = highlightSearchTerms($thisCity, $thisKeyword, $highlightColor); 
	$thisState_province = highlightSearchTerms($thisState_province, $thisKeyword, $highlightColor); 
	$thisCountry = highlightSearchTerms($thisCountry, $thisKeyword, $highlightColor); 
	$thisPostal_code = highlightSearchTerms($thisPostal_code, $thisKeyword, $highlightColor); 
	$thisPhone = highlightSearchTerms($thisPhone, $thisKeyword, $highlightColor); 
	$thisFax = highlightSearchTerms($thisFax, $thisKeyword, $highlightColor); 

?>
	<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 $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 nowrap><a href="edit.php?customer_idField=<?php echo $thisCustomer_id; ?>">修改</a></TD>
	<TD nowrap><a href="confirm_delete.php?customer_idField=<?php echo $thisCustomer_id; ?>">删除</a></TD>
	</TR>
<?php
		$i++;

	} 
?>
</TABLE>
<?php
} 
 ?>
<p>&nbsp;</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></p>

⌨️ 快捷键说明

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