[SOLVED] Search Script

This is a discussion on "[SOLVED] Search Script" within the PHP Forum section. This forum, and the thread "[SOLVED] Search Script are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Nov 14th, 2007, 17:31
Reputable Member
Join Date: Oct 2007
Location: Liverpool UK
Age: 29
Posts: 220
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Search Script

Does anyone have any good Php search Engine script??? I have some script and it does not seem to display any search results from my database..

Here is the script:

PHP: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search</title>
</head>
<body>
<h2>Search</h2> 
<form name="search" method="post" action="<?=$PHP_SELF?>">
Seach for: <input type="text" name="find" /> in 
<Select NAME="field">
<Option VALUE="fname">First Name</option>
<Option VALUE="lname">Last Name</option>
<Option VALUE="info">Profile</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</form>
</body>
<? 
//This is only displayed if they have submitted the form 
if ($searching =="yes"

echo 
"<h2>Results</h2><p>"
//If they did not enter a search term we give them an error 
if ($find == ""

echo 
"<p>You forgot to enter a search term"
exit; 

// Otherwise we connect to our Database 
mysql_connect("localhost""root""longstand1") or die(mysql_error()); 
mysql_select_db("dblearn") or die(mysql_error()); 
// We preform a bit of filtering 
$find strtoupper($find); 
$find strip_tags($find); 
$find trim ($find); 
//Now we search for our search term, in the field the user specified 
$data mysql_query("SELECT * FROM users WHERE upper($field) LIKE'%$find%'"); 
//And we display the results 
while($result mysql_fetch_array$data )) 

echo 
$result['fname']; 
echo 
" "
echo 
$result['lname']; 
echo 
"<br>"
echo 
$result['info']; 
echo 
"<br>"
echo 
"<br>"

//This counts the number or results - and if there wasn't any it gives them a little message explaining that 
$anymatches=mysql_num_rows($data); 
if (
$anymatches == 0

echo 
"Sorry, but we can not find an entry to match your query<br><br>"

//And we remind them what they searched for 
echo "<b>Searched For:</b> " .$find

?> 
</html>
Here is the database, the script is searching the table called users:

CREATE DATABASE IF NOT EXISTS dblearn;
USE dblearn;

CREATE TABLE users (fname VARCHAR(30), lname VARCHAR(30), info BLOB);
INSERT INTO users VALUES ( "Jim", "Jones", "In his spare time Jim enjoys biking, eating pizza, and classical music" ), ( "Peggy", "Smith", "Peggy is a water sports enthusiast who also enjoys making soap and selling cheese" ),( "Maggie", "Martin", "Maggie loves to cook itallian food including spagetti and pizza" ),( "Tex", "Moncom", "Tex is the owner and operator of The Pizza Palace, a local hang out joint" )
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Nov 14th, 2007, 18:10
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: Search Script

Here's a good one:
http://www.roscripts.com/PHP_search_engine-119.html

If you get stuck I can show you my source code.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Nov 14th, 2007, 18:19
Reputable Member
Join Date: Oct 2007
Location: Liverpool UK
Age: 29
Posts: 220
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Search Script

Hello Alex!

Yes please, i would love to see your search source code!

Cheers,
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Nov 14th, 2007, 18:33
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: Search Script

You will have to adapt from this!
PHP: Select all

class search {
function 
searchFor($s) {
    global 
$blog;
    
$blog->connectDB;
    
$sql "SELECT * FROM $blog->blogtbl WHERE title LIKE '%$s%' OR entry LIKE '%$s%' ORDER BY id DESC";
    
$query mysql_query($sql) or die(mysql_error());
    
$row_sql mysql_fetch_assoc($query);
    
$total mysql_num_rows($query);
    
$this->total $total;
        if(
$total 0) {
        
$this->query $query;
        return 
true;
        } else
            {
        return 
false;
        }
    }
    function 
showBlogs() {
                while (
$row mysql_fetch_assoc($this->query)) {//echo out the results
                        
echo '<div class="blogentry">
                        
                        <h3 class="blogtitle"><strong><a href="/blog/'
$row['link'], '">'$row['title'], '</a></strong></h3> - <span class="date">'strftime('%d %b %Y'$row['timestamp']), '</span>
                        
                        <span class="category">'
$row['cat'], '</span>
                        
                        <p>'
strip_tags(substr($row['entry'], 0100)), '.....</p>'// change 100 to be how many characters you want
                        
                        
'</div><hr class="break" />';
            }
    }
    function 
totalBlogs() {
    return 
$this->total;
    }
}

$search = new search
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Nov 14th, 2007, 18:35
Reputable Member
Join Date: Oct 2007
Location: Liverpool UK
Age: 29
Posts: 220
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Search Script

Thanks Alex,

Goodnight 2 You,

Some Rep added 4 u.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Nov 14th, 2007, 18:45
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: [SOLVED] Search Script

You're welcome
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Anyone have a working search form script? daveg33 PHP Forum 12 Sep 28th, 2007 23:54
Search script help Blake121 PHP Forum 5 May 7th, 2007 22:38
search box script geyids JavaScript Forum 7 Apr 9th, 2007 07:26
Search Engine Script dommox PHP Forum 4 Dec 29th, 2005 04:31
Looking for Search Script for CSS csa Web Page Design 5 Nov 23rd, 2005 22:34


All times are GMT. The time now is 06:44.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42