Submit Your Article Forum Rules

Results 1 to 2 of 2

Thread: PHP Site Search

  1. #1
    Senior Member
    Join Date
    Aug 2004
    Posts
    219

    PHP Site Search

    Hi All,

    I just finished my "beta" site search for one of the sites I maintain. I would appreciate it if you all could check it out and let me know what you think.

    You have to go to the site map, http://www.homesearch-md.com/site_map.html to use the search, and it's on the bottom of the page. Below is the php source that searches my database and arranges the results.

    I am looking for feedback on the results mainly, so anything you have to say works.

    <?
    $body_text = "";
    $search_complete = "no";
    $connection = @mysql_connect("host","username","password") or die (mysql_error());
    $db_name = "mydatabase";
    $search_text = $_POST['search_for'];
    if ($search_text != "") {
    echo "</head><body>";
    echo "$body_text";
    $search_result = "";
    while ($search_complete == "no") {
    $table_name = "pages";
    $search_by = "body_text";
    $db = @mysql_select_db($db_name, $connection) or die(mysql_error());
    $sql = "SELECT * FROM $table_name WHERE $search_by LIKE \"%%$search_text%%\"";
    $result = @mysql_query($sql, $connection) or die(mysql_error());
    while ($row = mysql_fetch_array($result)) {
    $id = $row['id'];
    $url_link = $row['url_link'];
    $url_title = $row['url_title'];
    $description = $row['description'];
    $body_words = $row['body_text'];
    $keywords = $row['keywords'];
    if ($search_text == $keywords && $search_text == $url_title && $search_text == $description) {
    $search_result .= "<font face=\"Arial\">
    <a href=\"$url_link\">$url_title</a>
    $description

    </font>";
    }
    if ($search_text == $keywords && $search_text == $description) {
    $search_result .= "<font face=\"Arial\">
    <a href=\"$url_link\">$url_title</a>
    $description

    </font>";
    }
    if ($search_text == $keywords) {
    $search_result .= "<font face=\"Arial\">
    <a href=\"$url_link\">$url_title</a>
    $description

    </font>";
    }
    if ($search_text == $description) {
    $search_result .= "<font face=\"Arial\">
    <a href=\"$url_link\">$url_title</a>
    $description

    </font>";
    } else {
    $search_result .= "<font face=\"Arial\">
    <a href=\"$url_link\">$url_title</a>
    $description

    </font>";
    }
    }
    $search_complete = "yes";
    }
    if ($search_result == "") {
    $search_result = "
    Sorry, No Matches. Try the <a href=\"http://www.homesearch-md.com/site_map.html\">Site Map</a>";
    }
    if ($search_complete == "yes") {
    $body_text .= "$search_result";
    }
    }
    ?>

  2. #2
    Senior Member
    Join Date
    Aug 2004
    Posts
    219

    Updated Search Function

    <?
    $body_text = "";
    $page = "";
    $search_complete = "no";
    $search_result = "";
    $omitted_search_result = "";
    $search_result_likely = "";
    $search_text = $_POST['search_for'];
    $connection = @mysql_connect("myhost","myuser","mypassword") or die (mysql_error());
    $db_name = "homesear_search";
    if ($search_text != "") {
    echo "</head><body>";
    while ($search_complete == "no") {
    $table_name = "pages";
    $search_by = "body_text";
    $db = @mysql_select_db($db_name, $connection) or die(mysql_error());
    $sql = "SELECT * FROM $table_name WHERE $search_by LIKE \"%%$search_text%%\"";
    $result = @mysql_query($sql, $connection) or die(mysql_error());
    while ($row = mysql_fetch_array($result)) {
    $id = $row['id'];
    $url_link = $row['url_link'];
    $url_title = $row['url_title'];
    $description = $row['description'];
    $body_words = $row['body_text'];
    $keywords = $row['keywords'];
    if ($keywords >= $search_text) {
    if ($description >= $search_text) {
    if ($url_title >= $search_text) {
    if ($url_link >= $search_text) {
    $search_result_likely .= "<font face=\"Arial\">
    <a href=\"links.php?id=$id&keywords=$search_text\">$u rl_title</a>
    $description</font>

    <font color=\"#008080\" size=\"2\">$url_link</font>

    ";
    } else {
    $search_result_likely .= "<font face=\"Arial\">
    <a href=\"links.php?id=$id&keywords=$search_text\">$u rl_title</a>
    $description</font>

    <font color=\"#008080\" size=\"2\">$url_link</font>

    ";
    }
    } else {
    $search_result_likely .= "<font face=\"Arial\">
    <a href=\"links.php?id=$id&keywords=$search_text\">$u rl_title</a>
    $description</font>

    <font color=\"#008080\" size=\"2\">$url_link</font>

    ";
    }
    } else {
    $search_result_likely .= "<font face=\"Arial\">
    <a href=\"links.php?id=$id&keywords=$search_text\">$u rl_title</a>
    $description</font>

    <font color=\"#008080\" size=\"2\">$url_link</font>

    ";
    }
    } else {
    $omitted_search_result .= "<font face=\"Arial\">
    <a href=\"links.php?id=$id&keywords=$search_text\">$u rl_title</a>
    $description</font>

    <font color=\"#008080\" size=\"2\">$url_link</font>

    ";
    }
    $search_result = "$search_result_likely $omitted_search_result";
    }
    $search_complete = "yes";
    }
    if ($search_result == "") {
    $search_result = "
    Sorry, No Matches. Try the <a href=\"http://www.homesearch-md.com/site_map.html\">Site Map</a>";
    }
    if ($search_complete == "yes") {
    $body_text .= "$search_result";
    }
    }

Similar Threads

  1. Upgrade search on your site with Google Custom Search Engine
    By danlefree in forum Web Programming Discussion Forum
    Replies: 33
    Last Post: 01-18-2010, 01:39 PM
  2. Why Google site search is not working in my site?
    By anittajoju in forum Google Discussion Forum
    Replies: 0
    Last Post: 12-22-2006, 12:49 AM
  3. site search
    By david123 in forum eCommerce Discussion Forum
    Replies: 4
    Last Post: 04-13-2005, 09:21 AM
  4. Seeing MSN Search Beta at Main Search Site
    By WPW_Feedbot in forum Search Engine Optimization Forum
    Replies: 0
    Last Post: 01-14-2005, 04:30 PM
  5. Site Search Large Site - Need Help!
    By greeneagle in forum Graphics & Design Discussion Forum
    Replies: 2
    Last Post: 01-17-2004, 08:06 PM

Posting Permissions

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