Welcome to WebmasterWorld Guest from 54.205.75.60

Forum Moderators: open

Message Too Old, No Replies

PHP/MYSQL searching text entries

programming blog system - need help with search

   
11:14 am on Apr 11, 2007 (gmt 0)

5+ Year Member



Hi--
Am creating a simple blog system for my use. So far progress has been good. Here's what I have:

MySQL Table with ID, Title, Content, Date

Enter new blog.
Add blog to displayed list as link.
Call up specific blog from above list--edit it and save it.

That's all well an good for me as the blogger. What I am stumped on is how best to search the contents of the Content item, when a visitor enters a keyword (or keywords) and return links to *only* those blogs that match the search words.

Any pointers much appreciated.

Thanks,
Clair

2:12 pm on Apr 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use a fulltext index. It will index fullwords in the content and is fairly fast. That sounds like what you are looking for.

JAG

4:31 pm on Apr 11, 2007 (gmt 0)

5+ Year Member



JAG --
Yeesh - three PHP / MySQL books and nothing about something called FULLTEXT. Will hit google for that BUT, in the meantime -- I'm having trouble with my query -- but it is so close it hurts.

Here's the one-line form that feeds the query:

<form action="search-blog.php" method="post">
<p>Search for: <input type="text" name="searchword" size="40" maxsize="100" /></p>
<input type="submit" name="submit" value="Go find!" />
</form>

And here's the query that has a syntax problem:

$query = "SELECT * FROM blog_entries WHERE MATCH
(blog_entry={$_GET['entry']}) AGAINST (searchterm={$_POST['searchword']})";

and here's the Error Msg.:

Check the manual that corresponds to your MySQL server version for the right syntax to use near '=) AGAINST (searchterm=testing)' at line 2. The query was SELECT * FROM blog_entries WHERE MATCH (blog_entry=) AGAINST (searchterm=testing).

Note: "testing" was a word I entered into the form.

I know this query is not what I finally want, but it would be useful at some point, it I could get this working.

Thanks much. I've pored over this character by character until I'm blue in the face! lol

Clair

4:49 pm on Apr 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



SELECT * FROM blog_entries WHERE MATCH (blog_entry=) AGAINST (searchterm=testing)

I usually use boolean mode so I'd use:

SELECT * FROM blog_entries WHERE MATCH (blog_entry) AGAINST ('+"testing"' in boolean mode)

That should work for you as long as the fulltext index is there.

JAG

6:31 pm on Apr 11, 2007 (gmt 0)

5+ Year Member



Hi justageek and Jag --

Just came back to tell you that I had everything working with FULLTEXT --
and found just's comment. Thanks!

I found the FULLTEXT help via Zend Developer and the got the query string sorted out with the help of phpfreaks.

Not bad -- whole thing working inside 1 hour (had lunch in the middle!)

Man, I am one happy camper.

Cheers,
Clair

7:09 pm on Apr 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Very good!

JAG

10:37 pm on Apr 11, 2007 (gmt 0)

5+ Year Member



lol
JAG --
I was so excited when I came back in to report success that I read Justageek in the side bar and thought it was a second person.

See - you can be in two places at once, or else beside yourself -- which was the case here.

Thanks JAG and only JAG -
Clair

11:47 pm on Apr 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



See - you can be in two places at once, or else beside yourself -- which was the case here

:-) We're ALL here to help!

JAG