01.
<form method=
"post"
action=
"searchtest.php"
accept-charset=
"utf-8"
>
02.
<input type=
"hidden"
name=
"submitted"
value=
"true"
>
03.
<label> Search Category :
04.
<select name=
"category"
>
05.
<option value=
"firstname"
>firstname</option>
06.
<option value=
"surname"
>surname</option>
07.
<option value=
"address"
>address</option>
08.
<option value=
"tel"
>tel</option>
09.
<option value=
"email"
>email</option>
10.
<option value=
"gender"
>gender</option>
11.
</select>
12.
</label>
13.
<label>Search : <input type=
"text"
name=
"search"
></label>
14.
<input type=
"submit"
name=
""
>
15.
</form>
16.
<?php
17.
if
(isset(
$_POST
[
'submitted'
])) {
18.
include
(
'connectdb.php'
);
19.
$category
=
$_POST
[
'category'
];
20.
$search
=
$_POST
[
'search'
];
21.
$query
=
"SELECT * FROM users WHERE $category LIKE '%"
.
$search
.
"%'"
;
22.
$result
= mysqli_query(
$conn
,
$query
)
or
die
(
'error'
);
23.
$user_data
=
array
();
24.
$num_rows
= mysqli_num_rows(
$result
);
25.
echo
"$num_rows result found"
;
26.
echo
"<table>"
;
27.
echo
"<tr><th>firstname</th><th>surname</th><th>address</th><th>tel</th><th>email</th><th style='text-align:right'>gender</th></tr>"
;
28.
while
(
$row
= mysqli_fetch_array(
$result
, MYSQLI_ASSOC)){
29.
echo
"<tr><td>"
;
30.
echo
$row
[
'firstname'
];
31.
echo
"</td><td>"
;
32.
echo
$row
[
'surname'
];
33.
echo
"</td><td>"
;
34.
echo
$row
[
'address'
];
35.
echo
"</td><td>"
;
36.
echo
$row
[
'tel'
];
37.
echo
"</td><td>"
;
38.
echo
$row
[
'email'
];
39.
echo
"</td><td style='text-align:right'>"
;
40.
echo
$row
[
'gender'
];
41.
echo
"</td></tr>"
;
42.
43.
$user_data
[] =
array
(
44.
'firstname'
=>
$row
[
"firstname"
],
45.
'surname'
=>
$row
[
"surname"
],
46.
'address'
=>
$row
[
"address"
],
47.
'tel'
=>
$row
[
"tel"
],
48.
'email'
=>
$row
[
"email"
],
49.
'gender'
=>
$row
[
"gender"
]
50.
);
51.
52.
}
53.
echo
"</table>"
;
54.
55.
56.
}
57.
?>