General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 21st, 2003, 03:32 PM
funkyM funkyM is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Australia
Posts: 13 funkyM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Having probs with fulltext search query

I have been reading the tutorial by Mitchell Harper on this site

Getting Started With MySQL's Full-Text Search Capabilities

I have given it a go and have come up trumps. I keep getting a mysql error message. But if I do a query on the table in phpMyAdmin it works great. Any help would be appreciated.

Here's the link

http://www.tnmarketing.com.au/fulltext/

Here's the html


<html>
<body>
<form method=post action=biz_listing_display.php>
<input type="text" size="20" name="keysearch">
<input type="submit" value=SEARCH>

</form>


</body>
</html>


Here's the php that processes it


<?

$database = "tnm";
$user = "tnm";
$pass ="booger";



@ $db = mysql_pconnect("localhost", "$user", "$pass");

if (!$db)
{
echo "Error: Could not connect to database. Please try again later.";
exit;
}


$query = "select firstName from testTable where match(firstName, lastName, details) against('ben')";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);



if(!$num_results == "0")
{

echo "<p>";
echo "<b>No. of results found:</b> ".$num_results;
echo "<p>";

for ($i=0; $i <$num_results; $i++)
{

$row = mysql_fetch_array($result);

echo "<b>First Name:</b> <font color=#FF6600><b>".stripslashes($row[firstName])."</b></font><br>";
echo "<b>Last Name:</b> ".stripslashes($row[lastName])."<br>";
echo "<b>Details:</b> ".stripslashes($row[details])."<br>";
echo "<p>";
}



}
else
{
echo "<center><font color=red><b>SORRY, NO MATCHING ENTRIES FOUND<br>TRY SEARCHING AGAIN!</b></font></ceter>";
}
?>

Last edited by funkyM : January 21st, 2003 at 03:52 PM.

Reply With Quote
  #2  
Old January 21st, 2003, 06:33 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,240 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 18
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Re: Having probs with fulltext search query

Quote:
Originally posted by funkyM
if(!$num_results == "0")


Try this instead:
PHP Code:
if ($num_results != 0


You can keep it the way you had it, just remove the double quotes around the 0... You're treating it as a String. I would, however, use the method above, as it's easier to read.

Hope that helps!
__________________
____________________________________________
Developer Shed Weekly Writer | DevArticles Forum Moderator
Build Your Own KlipFolio Klip With PHP
FrankManno.com - Under Construction
Design Interactive Group - Under Construction

Reply With Quote
  #3  
Old January 21st, 2003, 06:53 PM
funkyM funkyM is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Australia
Posts: 13 funkyM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
no go

Thanks for the hint I tried doing what you said but still no go I am getting the smae error

Regards

funky

Reply With Quote
  #4  
Old January 21st, 2003, 09:25 PM
Jeb. Jeb. is offline
"l33t? What's l33t?"
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 51 Jeb. User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Send a message via AIM to Jeb.
$result = mysql_query($query)

Because you're getting an invalid result error, it means your query isn't perfoming correctly. To find out what's up with your query, change that above line to this:

PHP Code:
 $result mysql_query($query) or die(mysql_error()); 


That should allow you to correct whatever is wrong.

-J
__________________
Jeb.

AIM: JebediahMc - PM Me - E-Mail Me


Reply With Quote
  #5  
Old January 21st, 2003, 10:10 PM
funkyM funkyM is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Australia
Posts: 13 funkyM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Problem exposed

Thankyou to all who have helped me especially you Jeb your little bit of error handling has mede me see the light.

Somehow I had forgotten the mysql_select_db() function and that's what was causing the problem.

Thankyou very much sometimes no matter how hard you look you just can't see the answer.

Kind regards to all

FunkyM

Reply With Quote
  #6  
Old January 21st, 2003, 10:32 PM
funkyM funkyM is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Australia
Posts: 13 funkyM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Angry Next Problem

Kind of got it working

except that it is now only displaying the business name only

to test it for yourself go to

http://www.tnmarketing.com.au and search for "total" go down the bottom of the page and do a search it's right next to the weather and you'll see what I mean.

Also just found that if I search for anything else I get an error


see code below


<?
$database = "";
$user = "";
$pass ="";



@ $db = mysql_pconnect("localhost", "$user", "$pass");

if (!$db)
{
echo "Error: Could not connect to database. Please try again later.";
exit;
}

mysql_select_db($database);
$query = "select biz_name, description, address, phone, fax, email, url from biz_listing where match biz_name, description against $keyword_search";
$result = mysql_query($query) or die(mysql_error());
$num_results = mysql_num_rows($result);



if($num_results != 0)
{

echo "<p>";
echo "<b>No. of results found:</b> ".$num_results;
echo "<p>";

for ($i=0; $i <$num_results; $i++)
{

$row = mysql_fetch_array($result);


$listing_no = ($i + 1);
echo "<b><big>$listing_no.</big></b> ";
echo "<b>Name:</b> <font color=#FF6600><b>".stripslashes($row[biz_name])."</b></font><br>";
echo "<b>Description:</b> ".stripslashes($row[description])."<br>";
echo "<b>Address:</b> ".stripslashes($row[address])."<br>";
echo "<b>Phone:</b> ".stripslashes($row[phone]);
echo " <b>Fax:</b> ";

if(stripslashes($row[fax]) == "")
echo "N/A ";
else
echo stripslashes($row[fax]);

echo " <b>Email:</b> ";
if(stripslashes($row[email]) == "")
echo "N/A &nbsp;<br>";
else
echo "<a href=mailto:".stripslashes($row[email]).">".stripslashes($row[email])."</a><br>";

echo " <b>URL:</b> ";
if(stripslashes($row[url]) == "")
echo "No URL Available<br>";
else
echo "<a href=http://".stripslashes($row[url]).">".stripslashes($row[url])."</a>";

echo "<p>";
}



}
else
{
echo "<center><font color=red><b>SORRY, NO MATCHING ENTRIES FOUND<br>TRY SEARCHING AGAIN!</b></font></ceter>";
}

?>

Last edited by funkyM : January 21st, 2003 at 10:40 PM.

Reply With Quote
  #7  
Old January 21st, 2003, 11:35 PM
Jeb. Jeb. is offline
"l33t? What's l33t?"
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 51 Jeb. User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Send a message via AIM to Jeb.
Re: Next Problem

Quote:
Originally posted by funkyM
Also just found that if I search for anything else I get an error


I haven't done anything with FT Searching before, so I can't answer your first question. However, I can throw a guess at the 2nd.

It appears that when doing a full text search, if no matches are found, MySQL doesn't return a standard 0 rows as it would with any other select query. (Don't quote me on that )

What you might want to do is add the error-supressing operator (@) on the beginning of your mysql_num_rows() function. That will remove your error - but be careful, it'll also hide any other errors you get with that function!

Reply With Quote
  #8  
Old January 21st, 2003, 11:43 PM
funkyM funkyM is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Australia
Posts: 13 funkyM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
No change still doing it

It made no difference damn it. I hate when this happens it is very frustrating.

Reply With Quote
  #9  
Old January 22nd, 2003, 01:23 AM
Jeb. Jeb. is offline
"l33t? What's l33t?"
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 51 Jeb. User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Send a message via AIM to Jeb.
$num_results = mysql_num_rows($result);

To

$num_results = @mysql_num_rows($result);

And that still gives you the mysql_num_rows() error? That can't be right.

Reply With Quote
  #10  
Old January 22nd, 2003, 02:59 PM
funkyM funkyM is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Australia
Posts: 13 funkyM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
My mistake

OK I added the @ and it now works except that it is only printing the name of the business.

http://www.tnmarketing.com.au

search for: total boulevarde


and you'll see

by the way if you can help me sort this out I'll send you a bottle of nice red. If you drink wine that is.


New Code:


<?
$database = "";
$user = "";
$pass ="";







@ $db = mysql_pconnect("localhost", "$user", "$pass");

if (!$db)
{
echo "Error: Could not connect to database. Please try again later.";
exit;
}

mysql_select_db($database);

// $query = "select biz_listing where match biz_name, description against $keyword_search as relevance from test table";

$query = "select biz_name, description match biz_name, description against $keyword_search as relevance from testTable where match biz_name, description against $keyword_search";

$result = mysql_query($query) or die(mysql_error());
$num_results = @mysql_num_rows($result);



if($num_results != 0)
{




echo "<p>";
echo "<b>No. of results found:</b> ".$num_results;
echo "<p>";

for ($i=0; $i <$num_results; $i++)
{

$row = mysql_fetch_array($result);


$listing_no = ($i + 1);
echo "<b><big>$listing_no.</big></b> ";
echo "<b>Name:</b> <font color=#FF6600><b>".stripslashes($row[biz_name])."</b></font><br>";
echo "<b>Description:</b> ".stripslashes($row[description])."<br>";
echo "<b>Address:</b> ".stripslashes($row[address])."<br>";
echo "<b>Phone:</b> ".stripslashes($row[phone]);
echo " <b>Fax:</b> ";

if(stripslashes($row[fax]) == "")
echo "N/A ";
else
echo stripslashes($row[fax]);

echo " <b>Email:</b> ";
if(stripslashes($row[email]) == "")
echo "N/A &nbsp;<br>";
else
echo "<a href=mailto:".stripslashes($row[email]).">".stripslashes($row[email])."</a><br>";

echo " <b>URL:</b> ";
if(stripslashes($row[url]) == "")
echo "No URL Available<br>";
else
echo "<a href=http://".stripslashes($row[url]).">".stripslashes($row[url])."</a>";

echo "<p>";
}



}
else
{
echo "<center><font color=red><b>SORRY, NO MATCHING ENTRIES FOUND<br>TRY SEARCHING AGAIN!</b></font></ceter>";
}

?>
Funky

Last edited by funkyM : January 22nd, 2003 at 03:33 PM.

Reply With Quote
  #11  
Old January 22nd, 2003, 07:03 PM
Jeb. Jeb. is offline
"l33t? What's l33t?"
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 51 Jeb. User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Send a message via AIM to Jeb.
Ok, I've done a bit of reading on FullText searching, and here's what I'm thinking:

Code:
select biz_name, description match biz_name, description against $keyword_search as relevance from testTable where match biz_name, description against $keyword_search


Perhaps you could try and write it syntactically correct, and see if that makes any difference:

Code:
SELECT biz_name, description FROM textTable WHERE MATCH(biz_name,description) AGAINST('$keyword_search')


See if that works as expected.

Reply With Quote
  #12  
Old January 22nd, 2003, 07:47 PM
funkyM funkyM is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Australia
Posts: 13 funkyM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
same error

when I tried that it gave me the same MYSQL error as usual

Reply With Quote
  #13  
Old January 22nd, 2003, 11:50 PM
Jeb. Jeb. is offline
"l33t? What's l33t?"
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 51 Jeb. User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Send a message via AIM to Jeb.
echo() the value of $result and see if it's actually a resource ID or not.

Reply With Quote
  #14  
Old January 23rd, 2003, 12:03 AM
funkyM funkyM is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Australia
Posts: 13 funkyM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
how

how do I do that

echo $result;

wright or wrong

Reply With Quote
  #15  
Old January 23rd, 2003, 01:19 AM
Jeb. Jeb. is offline
"l33t? What's l33t?"
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 51 Jeb. User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Send a message via AIM to Jeb.
That's correct. While you're at it, use print_r($row) to print the value of the $row array from MySQL.

Then try searching for total boulevard and see what it says.

Reply With Quote
  #16  
Old January 27th, 2003, 03:35 PM
funkyM funkyM is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Australia
Posts: 13 funkyM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Problem solved

I have corrected my SQL and away she goes. Thanks Jeb.

Email me you address and I'll send you a bottle of red.

Regards

Paul

Reply With Quote
  #17  
Old January 27th, 2003, 05:58 PM
Jeb. Jeb. is offline
"l33t? What's l33t?"
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 51 Jeb. User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Send a message via AIM to Jeb.
Good work

Ah, sorry, but I don't drink Use it yourself to toast solving the problem, heh

Glad to help,
-Jeb.

Reply With Quote
  #18  
Old January 27th, 2003, 11:24 PM
funkyM funkyM is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Australia
Posts: 13 funkyM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks Jeb

I really appreciate that Jeb, more than you'll ever know.

Kindest regards

Paul Kovac

Reply With Quote
  #19  
Old April 5th, 2003, 11:35 AM
shaishiv shaishiv is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 1 shaishiv User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Re: Thanks Jeb

Hey Jeb!

You have helped a lot of people on full text search. Here is my problem- I am looking for a boolean full text search engine which could help me like this - If I put something like cat+photo then it should give me all the records containing cat and photo.
I will highly appreciate your help ASAP. You can't imagine how much in trouble I am. Please if possible then gimme the code.
Thanks a lot!!!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Having probs with fulltext search query


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap