登录 | 注册 | FAQ
Anonymous

How to add search box

+ 发表回复

5 篇帖子 分页: 1 / 1


How to add search box

Jawad adil » 周三 4月 08, 2015 7:22 am

How can i add search box to my website. I did all the coding plus my website is now ready but i didnt have search box on it. Tell me how can i add a search box to my site?
头像

Jawad adil

  • 帖子: 2
  • 注册: 周二 4月 07, 2015 8:16 am

Re: How to add search box

Chikwado » 周四 4月 09, 2015 7:24 am

最后由 Chikwado 编辑于 周二 5月 19, 2015 5:16 pm,总共编辑了 5 次

头像

Chikwado

  • 帖子: 87
  • 注册: 周一 7月 29, 2013 11:36 pm
  • 地址: Nigeria
--
Focus On Advance Science And Programming.

Re: How to add search box

Jawad adil » 周五 4月 10, 2015 1:21 pm

What should i have to write in javascript i wrote a script but i dosnt do nothing.i am not a professional please help me in detail
头像

Jawad adil

  • 帖子: 2
  • 注册: 周二 4月 07, 2015 8:16 am

Re: How to add search box

XainPro » 周三 4月 15, 2015 5:41 pm

making a search from is advanced level thing you need to learn php for this

http://html.net/tutorials/php/
头像

XainPro

  • 帖子: 3933
  • 注册: 周五 2月 17, 2012 8:10 pm

Re: How to add search box

Veeramanikandan » 周四 5月 14, 2015 2:51 pm

<?php
$query = $_GET['query'];
// gets value sent over search form

$min_length = 3;
// you can set minimum length of the query if you want

if(strlen($query) >= $min_length){ // if query length is more or equal minimum length then

$query = htmlspecialchars($query);
// changes characters used in html to their equivalents, for example: < to &gt;

$query = mysql_real_escape_string($query);
// makes sure nobody uses SQL injection

$raw_results = mysql_query("SELECT * FROM articles
WHERE (`title` LIKE '%".$query."%') OR (`text` LIKE '%".$query."%')") or die(mysql_error());

// * means that it selects all fields, you can also write: `id`, `title`, `text`
// articles is the name of our table

// '%$query%' is what we're looking for, % means anything, for example if $query is Hello
// it will match "hello", "Hello man", "gogohello", if you want exact match use `title`='$query'
// or if you want to match just full word so "gogohello" is out use '% $query %' ...OR ... '$query %' ... OR ... '% $query'

if(mysql_num_rows($raw_results) > 0){ // if one or more rows are returned do following

while($results = mysql_fetch_array($raw_results)){
// $results = mysql_fetch_array($raw_results) puts data from database into array, while it's valid it does the loop

echo "<p><h3>".$results['title']."</h3>".$results['text']."</p>";
// posts results gotten from database(title and text) you can also show id ($results['id'])
}

}
else{ // if there is no matching rows do following
echo "No results";
}

}
else{ // if query length is less than minimum
echo "Minimum length is ".$min_length;
}
?>
头像

Veeramanikandan

  • 帖子: 20
  • 注册: 周一 9月 22, 2014 4:03 pm


+ 发表回复

分页: 1 / 1