Results 1 to 4 of 4

Thread: [RESOLVED] Display Search Results Question

  1. #1

    Thread Starter
    Addicted Member kzatu's Avatar
    Join Date
    Aug 2003
    Location
    Nevada
    Posts
    148

    Resolved [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.
    Changes are not permanent, but change is. {Neil Peart}

  2. #2
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: Display Search Results Question

    Here You !
    vb Code:
    1. <?php
    2. $query='SELECT * FROM table WHERE content like "%'.$search.'%"';
    3.  
    4. while ($row=mysql_fetch_array($sqlresult)) {
    5. ?>
    6.  
    7. Your Name is
    8. <?php
    9. echo $row['name'];
    10. ?>
    11.  
    12. email is
    13. <?php
    14. echo $row['email'];
    15. ?>
    16.  
    17. .........
    18. <?php
    19.   }
    20. mysql_close();
    21. ?>

  3. #3

    Thread Starter
    Addicted Member kzatu's Avatar
    Join Date
    Aug 2003
    Location
    Nevada
    Posts
    148

    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:
    Chuck Norris
    Mini Biography: Chuck Norris is an Executive Producer of "Walker, Texas Ranger" (1993) as well as the star... more ...
    www.imdb.com/name/nm0001569
    How would I (in PHP or MySQL) return x number of words before and x number of words after the search term "Chuck Norris"
    Changes are not permanent, but change is. {Neil Peart}

  4. #4

    Thread Starter
    Addicted Member kzatu's Avatar
    Join Date
    Aug 2003
    Location
    Nevada
    Posts
    148

    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.
    Changes are not permanent, but change is. {Neil Peart}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width