搜索自动推荐 输入框推荐相近搜索 可以带图标
不同于一般的推荐,这个自动推荐可以添加图片在推荐框,也可以无刷新返回值
SQL Code
- CREATE TABLE IF NOT EXISTS `people2014` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `name` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
- `description` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
- `photo` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
- PRIMARY KEY (`id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=32
XML/HTML Code
- <form>
- <p>The auto-suggest can also display image thumbnail and additional description. You have to pass two additional parameters, <b>showThumbnail</b>, and <b>showDescription</b> and then set their value to <b>true</b>.</p>
- Public figure name : <input type="text" name="text3" id="text3" />
- <script language="javascript" type="text/javascript">
- $("#text3").coolautosuggest({
- url:"data.php?chars=",
- showThumbnail:true,
- showDescription:true
- });
- </script>
- </form>
JavaScript Code
- <script>
- $('#fieldset1, #fieldset7').coolfieldset();
- $('#fieldset2, #fieldset3, #fieldset4, #fieldset5, #fieldset6').coolfieldset({collapsed:true});
- </script>
PHP Code
- $arr=array();
- $result=mysql_query("SELECT * FROM people2014 WHERE name LIKE '%".mysql_real_escape_string($_GET['chars'])."%' ORDER BY name LIMIT 0, 10") ;
- if(mysql_num_rows($result)>0){
- while($data=mysql_fetch_row($result)){
- // Store data in array
- $arr[]=array("id" => $data[0], "data" => $data[1], "thumbnail" => 'thumbnails/'.$data[3], "description" => $data[2]);
- }
- }
- // Encode it with JSON format
- echo json_encode($arr);
PHP Code
- $arr=array();
- $result=mysql_query("SELECT * FROM people2014 WHERE name LIKE '%".mysql_real_escape_string($_GET['chars'])."%' ORDER BY name LIMIT 0, 10") ;
- if(mysql_num_rows($result)>0){
- while($data=mysql_fetch_row($result)){
- // Store data in array
- $arr[]=array("id" => $data[0], "data" => $data[1], "thumbnail" => 'thumbnails/'.$data[3], "description" => $data[2]);
- }
- }
- // Encode it with JSON format
- echo json_encode($arr);
原文地址:http://www.freejs.net/article_biaodan_365.html