php tutorial database tutorial content search (search for the specified content and output)
/ *
First let's create a search data table
create table if not exists `search` (
`id` int (4) not null auto_increment,
`keyword` varchar (500) not null,
primary key (`id`)
) engine = myisam default charset = utf8 auto_increment = 1;
save data
insert into `acc`.`search` (
`id`,
`keyword`
)
values (
null, 'content search'
), (
null, 'php site search'
); * /
//Data Connections
$ conn = mysql tutorial _connect ('localhost', 'ac', '1'); / / Here ac user name, a password is changed to your own mysql
$ res = mysql_db_query ('abc', "select * from search where keyword = 'content search'") or die (mysql_error ());
if (mysql_num_rows ($ res) == 1) {
while ($ row = mysql_fetch_assoc ($ res)) {
foreach ($ row as $ key => $ val) {
echo $ row ['keyword'], '<br>';
}
}
}
/ *
The principle is very simple to achieve According to the data submitted by the user mysql data table query whether the same, there is no output will not operate. This is a simple record search code.
Reproduced original source indicate the source www.jzread.com