01.
<?php
02.
03.
$hostname
=
"localhost"
;
04.
$user
=
"root"
;
05.
$password
=
"cpe52363172"
;
06.
$dbname
=
"test"
;
07.
$tblname
=
"coffee"
;
08.
09.
mysql_connect(
$hostname
,
$user
,
$password
)
or
die
(
"ติดต่อฐานข้อมูลไม่ได้"
);
10.
11.
mysql_select_db(
$dbname
)
or
die
(
"เลือกฐานข้อมูลไม่ได้"
);
12.
13.
$sql
=
"select * from $tblname where $field_search = '$%search%' "
;
14.
15.
$dbquery
= mysql_db_query(
$dbname
,
$sql
);
16.
17.
$num_rows
= mysql_num_rows(
$dbquery
);
18.
19.
$num_fields
= mysql_num_fields(
$dbquery
);
20.
21.
echo
"<Font color=blue>แสดงผลการค้นหาข้อมูลที่มีคำว่า </Font><Font color=red>"
.
$search
."</Font>
22.
<Font color=blue>ในฟิลด์ </Font><Font color=red>
".$field_search."
</Font>";
23.
echo
"<Table border=1>"
;
24.
echo
"<Tr>"
;
25.
26.
27.
$i
=0;
28.
while
(
$i
<
$num_fields
)
29.
{
30.
$field_name
[
$i
] = mysql_field_name(
$dbquery
,
$i
);
31.
echo
"<Td bgcolor=skyblue>"
.
$field_name
[
$i
].
"</Td>"
;
32.
$i
++;
33.
}
34.
35.
$i
=0;
36.
while
(
$i
<
$num_rows
)
37.
{
38.
$result
= mysql_fetch_array(
$dbquery
);
39.
$name
=
$result
[name];
40.
$type
=
$result
[type];
41.
$quantity
=
$result
[quantity];
42.
43.
echo
"<Tr><Td>$name</Td><Td>$type</Td><Td>$quantity</Td></Tr>"
;
44.
$i
++;
45.
}
46.
echo
"</Table>"
;
47.
48.
49.
echo
"<Br>ค้นพบ<Font color=red>"
.
$i
.
"เรกคอร์ด"
;
50.
echo
"<Br><Br><A Href = >"
.
"ex10_09.php"
.
">กลับไปค้นหาใหม่ </A>"
;
51.
52.
53.
mysql_close();
54.
?>