SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict sorin21us's Avatar
    Join Date
    Mar 2009
    Posts
    279
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A little help with a search engine

    I want to build a search engine for my site. I have the code that brings me from the database only the title that has the keywords that I searched for. Can someone, please, give a help with what I have to put next in my code to bring from the database and the content with dots between searched words like a normal search engine?

    This is my code so far:

    PHP Code:
    <?php include_once("mysql_connect.php");
    if(isset(
    $_POST['submit'])){
    $problem FALSE;
    if(empty(
    $_POST['search'])){
    $problem TRUE;
    echo 
    "<p style=\"color:#FF0000;\">Please enter a search term!</p>";
    }

    if(!
    $problem){
    $text $_POST['search']; 

    $query "SELECT * from news_posts WHERE title LIKE '%$text%' OR post LIKE '%$text%' OR author LIKE '%$text%'";
    $result = @mysql_query($query);
    $query2 "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts ORDER BY id DESC limit 15";
    $result2 = @mysql_query($query);

    if(
    $result && $result2){
    echo 
    "<h1>found " mysql_num_rows($result) . " results</h1><br />";
    echo 
    "<ul>";
    while (
    $row mysql_fetch_array($resultMYSQL_ASSOC)){
    $mess=$row['post'];
    $view 'page.php?id=' $row['id'];
    echo 
    '<li>' $row['id'] . ' - <a href="' $view '">' $row['title'] . '</a> - ' $row['author'] . '</li>';
    }
    echo 
    "</ul><br />
    <a href=\"search.php\">Search Again?</a>"
    ;
    }
    else
    {
    echo 
    "No posts matched your query";
    }
    }
    }
    else
    {
    ?>
    <form id="search" action="search.php?search" method="post">
    Keyword: <input type="text" name="search" size="30" class="text" /><br />
    <input type="submit" name="submit" value="Search" />
    </form>
    <?php

    ?>

  2. #2
    SitePoint Zealot
    Join Date
    Apr 2009
    Location
    South Florida
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try couple of these PHP script to get more ideas
    http://php.resourceindex.com/Complet...pts/Searching/

  3. #3
    SitePoint Addict sorin21us's Avatar
    Join Date
    Mar 2009
    Posts
    279
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lphy View Post
    Try couple of these PHP script to get more ideas
    http://php.resourceindex.com/Complet...pts/Searching/
    I will try what is on that site. Thank you.


Bookmarks

Posting Permissions

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