|
 |
|
ขอคัวอย่าง dropdownlist search หน่อยครับ เป็นแบบ PHP+Mysql ไม่รู้จะเริ่มยังไง |
|
 |
|
|
 |
 |
|
ถ้ามี2ช่องดังภาพก็แบบนี้เลยคับ
$sql = "select * from tb_name where data1 like '%$search1%' and data2 like '%$search2%' ";
|
 |
 |
 |
 |
Date :
2010-09-24 11:15:55 |
By :
noomthapla |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<form name="frmSearch" method="post" action="<?=$_SERVER['SCRIPT_NAME'];?>">
<table width="599" border="1">
<tr>
<th>Country Code
<select name="ddlCountryCode" id="ddlCountryCode">
<option>- Select Country Code -</option>
<option value="TH">TH</option>
<option value="EN">EN</option>
<option value="US">US</option>
</select>
Keyword
<input name="txtKeyword" type="text" id="txtKeyword" value="<?=$_POST["txtKeyword"];?>">
<input type="submit" value="Search"></th>
</tr>
</table>
</form>
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
// Search By Name or Email
$strSQL = "SELECT * FROM customer WHERE 1 ";
if($_POST["ddlCountryCode"] != "")
{
$strSQL .= " AND (CountryCode = '".$_POST["ddlCountryCode"]."') ";
}
if($_POST["txtKeyword"] != "")
{
$strSQL .= " AND (Name LIKE '%".$_POST["txtKeyword"]."%' or Email LIKE '%".$_POST["txtKeyword"]."%' ) ";
}
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="98"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="59"> <div align="center">Budget </div></th>
<th width="71"> <div align="center">Used </div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td><div align="center"><?=$objResult["CustomerID"];?></div></td>
<td><?=$objResult["Name"];?></td>
<td><?=$objResult["Email"];?></td>
<td><div align="center"><?=$objResult["CountryCode"];?></div></td>
<td align="right"><?=$objResult["Budget"];?></td>
<td align="right"><?=$objResult["Used"];?></td>
</tr>
<?
}
?>
</table>
<?
mysql_close($objConnect);
?>
</body>
</html>
|
 |
 |
 |
 |
Date :
2011-09-18 15:34:10 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ที่ยกตัวอย่างมา ก็มีแล้วคะ ขอบคุณที่ยกตัวอย่างมานะคะ อยากได้แบบที่ตั้กระทู้ไว้คะ
|
 |
 |
 |
 |
Date :
2011-12-18 16:29:00 |
By :
Sj |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จัดไปครับ ลองเอาไปใช้ดูครับ
Code (PHP)
<form name="frmSearch" method="get" action="<?=$_SERVER['SCRIPT_NAME']; ?>">
<TABLE width="94%" align="right">
<TR align="right" valign="bottom">
<td width="50%"></td>
<TD>
<SELECT NAME="type_search">
<? if($_GET["type_search"]=="employee.firstname"){?>
<OPTION VALUE="user.username" >ชื่อผู้ใช้</OPTION>
<OPTION VALUE="employee.emp_id">รหัสบุคลากร</OPTION>
<OPTION VALUE="employee.name"SELECTED>ชื่อบุคลากร</OPTION>
<? }else if($_GET["type_search"]=="employee.emp_id"){?>
<OPTION VALUE="user.username" >ชื่อผู้ใช้</OPTION>
<OPTION VALUE="employee.emp_id"SELECTED>รหัสบุคลากร</OPTION>
<OPTION VALUE="employee.firstname">ชื่อบุคลากร</OPTION>
<? }else{?>
<OPTION VALUE="user.username" SELECTED>ชื่อผู้ใช้</OPTION>
<OPTION VALUE="employee.emp_id">รหัสบุคลากร</OPTION>
<OPTION VALUE="employee.firstname">ชื่อบุคลากร</OPTION>
<? }?>
</SELECT>
</TD>
<td><input name="keyword" type="text" value="<?=$_GET["keyword"];?>" size="40"></td>
<td><input type="image" src="images/zoom.png" width="25" height="25"alt="ค้นหา" /></td>
<td><input type="button" onClick="javascript:location='show_emp.php'" value="ยกเลิก" class="button"></td>
</TR>
</TABLE>
</form>
<?
$keyword = $_GET["keyword"];
$type_search = $_GET["type_search"];
$sql_total="select* from user , employee where user.emp_id=employee.emp_id";
if($type_search) { $sql_total .= " and $type_search like '%$keyword%'"; }
$result_total=mysql_query($sql_total)or die("Error Query[".$sql_total."]");
$total = mysql_num_rows($result_total);
?>
|
 |
 |
 |
 |
Date :
2011-12-18 16:35:52 |
By :
000su000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|