[SOLVED] Partial Search Query

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



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > Databases

Notices


Reply
 
LinkBack Thread Tools
  #1  
Old Nov 6th, 2007, 23:41
Junior Member
Join Date: Nov 2007
Location: Michigan
Age: 22
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Partial Search Query

I'm having trouble with this query: what's the syntax I need to use so that it will search to see if a field has a partial name?

The system I have reads from an RSS feed, and posts topics on my forums from it. It takes two variables from the feed to create the title, which is done in a "Name - Class" format. This query is to search for just the name part, so how can I do it so it will query the database and pull the appropriate part knowing just the first part?

Thanks in advance!
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 7th, 2007, 04:51
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Partial Search Query

Code: Select all
SELECT text FROM table_name WHERE name = $name
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 7th, 2007, 05:05
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Partial Search Query

If the info you have is in the one column, you will need to use LIKE

Code: Select all
SELECT this FROM that_table WHERE name LIKE '%$name - %'
Cheers,
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
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 7th, 2007, 06:00
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: Partial Search Query

Here is a class file I have written, it searches or the provided word returning true or false if something is found then adds it to data member.
The second function will show all the results and the third tells us how many blog entries there are.

You will need to edit the SQL and how is outputted in the second function.

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;
    }

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 7th, 2007, 12:20
Junior Member
Join Date: Nov 2007
Location: Michigan
Age: 22
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Partial Search Query

I didn't know it would be as simple as LIKE =)

That should do it, going to update scripts right now. Thank you
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 7th, 2007, 15:26
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] Partial Search Query

There are more advanced methods which give much better results, but I created that for my blog and it worked fine.
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
Search Bar CONCAT query meth8200 Databases 2 May 13th, 2008 22:00
[SOLVED] Nightmare query AdRock Databases 0 Nov 17th, 2007 15:50
search query to google as <iframe> source vHTML JavaScript Forum 1 Jan 14th, 2007 17:52
[SOLVED] asp / sql query Anonymous User Classic ASP 4 Nov 19th, 2004 08:39


All times are GMT. The time now is 05:57.


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