CREATE TABLE `fangke_cc`.`search` ( `id` INT( 4 ) NOT NULL AUTO_INCREMENT , `keyword` VARCHAR( 20 ) NOT NULL , PRIMARY KEY ( `id` ) ) ENGINE = MYISAM
INSERT INTO `search` (`id`, `keyword`) VALUES (1, '中国脚本编程第一站www.jb51.net'), (2, '中国脚本编程第一站www.jb51.net'), (3, '中国脚本编程第一站www.jb51.net'), (4, '中国脚本编程第一站www.jb51.net');
if( $_POST) { $db ='fangke_cc'; mysql_pconnect('localhost','root','root') or die(mysql_error()); mysql_select_db($db); mysql_query("set names 'gbk'"); $key = $_POST['keyword']; $sql = "Select * from search where keyword like '%$key%'"; $query = mysql_query($sql); while( $rs = mysql_fetch_array( $query ) ) { echo str_replace($key,"<b>$key</b>",$rs['keyword']),'<br />'; } } ?> <form name="form1" method="post" action=""> <label> <input name="keyword" type="text" id="keyword"> </label> <label> <input type="submit" name="Submit" value="提交"> </label> </form>
希望本文所述对大家的php程序设计有所帮助。