etsted Posted February 7, 2014 Share Posted February 7, 2014 i have a search script i want to customize. i want to be able to search for something. Then the objekt i am searching for whit the highest result, "keywords", in it would be displayed first. Right now i shows me everything i search for according to the id. <h1>Search:</h1> <form action="search.php" method="get" class="search"> <input type="text" name="k" size='50' /> <input type="submit" name="submit" value='Search' /> </form> <?php $username = $_SESSION['username']; if(isset($username)) { include "navigator/navigator_login.php"; } else { include "navigator/navigator.php"; } ?> <hr /> <?php // also check out facebook and twitter like buttons include "connect.php"; $k = mysqli_real_escape_string($con, htmlentities(trim($_GET['k']))); $terms = explode(" ", $k); $query = "SELECT * FROM videos WHERE "; $i = 0; foreach($terms as $each) { $i++; if($i == 1) { $query .= "description LIKE '%$each%' "; } else { $query .= "OR description LIKE '%$each%' "; } } $result = mysqli_query($con, $query) or die(mysqli_error($con)); $numrows = mysqli_num_rows($result); if($numrows > 0) { while($row = mysqli_fetch_array($result)) { $id = $row['id']; $title = $row['title']; $url = $row['url']; $description = $row['description']; if($k == "") { echo ""; } else { echo "<h3><a href='$url'>$title</a></h3> $description"; } } } else { echo "no results on $k"; } mysqli_close($con); ?> Link to comment Share on other sites More sharing options...
justsomeguy Posted February 7, 2014 Share Posted February 7, 2014 Look over the various search options: https://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now