php database content search (search for specified content and output)

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags content data default key mysql network network programming php

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.