[RESOLVED] Display Search Results Question
I'm using PHP to query a MySQL database. When I get the results, I want to display all the records to the user but I only want to display so many words that come before and after the search word. Like show the 10 words that precede the search word and the 10 words that come after the search word.
Basically in PHP I have a simple query structure like,
PHP Code:
$query='SELECT * FROM table WHERE content like "%'.$search.'%"';
$row=mysql_fetch_array($sqlresult);
But since CONTENT can contain paragraphs of information, I want to strip it down before I display it to the user.
I'm not sure if MySQL has a function to do this, but if it does, I'd be willing to use it instead of PHP.
Re: Display Search Results Question
Here You !
vb Code:
<?php
$query='SELECT * FROM table WHERE content like "%'.$search.'%"';
while ($row=mysql_fetch_array($sqlresult)) {
?>
Your Name is
<?php
echo $row['name'];
?>
email is
<?php
echo $row['email'];
?>
.........
<?php
}
mysql_close();
?>
Re: Display Search Results Question
Thanks for chipping in killer7k but I think you missed the question or perhaps I didn't post it well enough. I want to return search results similar to most search engines where they show you a snipet of information of what comes before and after your search terms.
For example, let's say that I search the web for "Chuck Norris". One of the search results might be a URL to his biography on IMDB. And below the link they will show a preview of what they found on the web page. That preview might look like this:
How would I (in PHP or MySQL) return x number of words before and x number of words after the search term "Chuck Norris"
Re: Display Search Results Question
I actually found a post on PHP where someone wrote their own function to handle this. It is called cuttext and I found it here. Works really nice.