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>Country Code
10.
<select name=
"ddlCountryCode"
id=
"ddlCountryCode"
>
11.
<option>- Select Country Code -</option>
12.
<option value=
"TH"
>TH</option>
13.
<option value=
"EN"
>EN</option>
14.
<option value=
"US"
>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
[
"ddlCountryCode"
] !=
""
)
29.
{
30.
$strSQL
.=
" AND (CountryCode = '"
.
$_POST
[
"ddlCountryCode"
].
"') "
;
31.
}
32.
if
(
$_POST
[
"txtKeyword"
] !=
""
)
33.
{
34.
$strSQL
.=
" AND (Name LIKE '%"
.
$_POST
[
"txtKeyword"
].
"%' or Email LIKE '%"
.
$_POST
[
"txtKeyword"
].
"%' ) "
;
35.
}
36.
$objQuery
= mysql_query(
$strSQL
)
or
die
(
"Error Query ["
.
$strSQL
.
"]"
);
37.
?>
38.
<table width=
"600"
border=
"1"
>
39.
<tr>
40.
<th width=
"91"
> <div align=
"center"
>CustomerID </div></th>
41.
<th width=
"98"
> <div align=
"center"
>Name </div></th>
42.
<th width=
"198"
> <div align=
"center"
>Email </div></th>
43.
<th width=
"97"
> <div align=
"center"
>CountryCode </div></th>
44.
<th width=
"59"
> <div align=
"center"
>Budget </div></th>
45.
<th width=
"71"
> <div align=
"center"
>Used </div></th>
46.
</tr>
47.
<?
48.
while
(
$objResult
= mysql_fetch_array(
$objQuery
))
49.
{
50.
?>
51.
<tr>
52.
<td><div align=
"center"
><?=
$objResult
[
"CustomerID"
];?></div></td>
53.
<td><?=
$objResult
[
"Name"
];?></td>
54.
<td><?=
$objResult
[
"Email"
];?></td>
55.
<td><div align=
"center"
><?=
$objResult
[
"CountryCode"
];?></div></td>
56.
<td align=
"right"
><?=
$objResult
[
"Budget"
];?></td>
57.
<td align=
"right"
><?=
$objResult
[
"Used"
];?></td>
58.
</tr>
59.
<?
60.
}
61.
?>
62.
</table>
63.
<?
64.
mysql_close(
$objConnect
);
65.
?>
66.
</body>
67.
</html>