01.
<html>
02.
<head>
03.
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
04.
</head>
05.
<body>
06.
<form name=
"frmSearch"
method=
"post"
action=
"<?=$_SERVER['SCRIPT_NAME'];?>"
>
07.
<table width=
"599"
border=
"1"
>
08.
<tr>
09.
<th>Select
10.
<select name=
"ddlSelect"
id=
"ddlSelect"
>
11.
<option>- Select -</option>
12.
<option value=
"CustomerID"
<?
if
(
$_POST
[
"ddlSelect"
]==
"CustomerID"
){
echo
"selected"
;}?>>CustomerID</option>
13.
<option value=
"Name"
<?
if
(
$_POST
[
"ddlSelect"
]==
"Name"
){
echo
"selected"
;}?>>Name</option>
14.
<option value=
"Email"
<?
if
(
$_POST
[
"ddlSelect"
]==
"Email"
){
echo
"selected"
;}?>>US</option>
15.
</select>
16.
Keyword
17.
<input name=
"txtKeyword"
type=
"text"
id=
"txtKeyword"
value=
"<?=$_POST["
txtKeyword
"];?>"
>
18.
<input type=
"submit"
value=
"Search"
></th>
19.
</tr>
20.
</table>
21.
</form>
22.
<?
23.
24.
$objConnect
= mysql_connect(
"localhost"
,
"root"
,
"root"
)
or
die
(
"Error Connect to Database"
);
25.
$objDB
= mysql_select_db(
"mydatabase"
);
26.
27.
$strSQL
=
"SELECT * FROM customer WHERE 1 "
;
28.
if
(
$_POST
[
"ddlSelect"
] !=
""
and
$_POST
[
"txtKeyword"
] !=
''
)
29.
{
30.
$strSQL
.=
" AND ("
.
$_POST
[
"ddlSelect"
].
" LIKE '%"
.
$_POST
[
"txtKeyword"
].
"%' ) "
;
31.
}
32.
33.
34.
$objQuery
= mysql_query(
$strSQL
)
or
die
(
"Error Query ["
.
$strSQL
.
"]"
);
35.
?>
36.
<table width=
"600"
border=
"1"
>
37.
<tr>
38.
<th width=
"91"
> <div align=
"center"
>CustomerID </div></th>
39.
<th width=
"98"
> <div align=
"center"
>Name </div></th>
40.
<th width=
"198"
> <div align=
"center"
>Email </div></th>
41.
<th width=
"97"
> <div align=
"center"
>CountryCode </div></th>
42.
<th width=
"59"
> <div align=
"center"
>Budget </div></th>
43.
<th width=
"71"
> <div align=
"center"
>Used </div></th>
44.
</tr>
45.
<?
46.
while
(
$objResult
= mysql_fetch_array(
$objQuery
))
47.
{
48.
?>
49.
<tr>
50.
<td><div align=
"center"
><?=
$objResult
[
"CustomerID"
];?></div></td>
51.
<td><?=
$objResult
[
"Name"
];?></td>
52.
<td><?=
$objResult
[
"Email"
];?></td>
53.
<td><div align=
"center"
><?=
$objResult
[
"CountryCode"
];?></div></td>
54.
<td align=
"right"
><?=
$objResult
[
"Budget"
];?></td>
55.
<td align=
"right"
><?=
$objResult
[
"Used"
];?></td>
56.
</tr>
57.
<?
58.
}
59.
?>
60.
</table>
61.
<?
62.
mysql_close(
$objConnect
);
63.
?>
64.
</body>
65.
</html>