Programming Tools
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingProgramming Tools

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:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old January 21st, 2003, 05:47 AM
funkyM funkyM is offline
Junior Member
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
Unhappy Full text search woes

I have recently implemented a facility on my site so that local business owners can add a business listing on my site.

I read your article as I am interested in performing full text searches on the business name and description fields in the table.

The problem is that I keep getting a mysql error

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/tnm/web/tnm/biz_listing_display.php on line 64

The usual thing telling me that somthing about my query is incorrect.

I am using phpMyAdmin to administer my tables.

My table contains a number of fields but I am only searching on biz_name and description.

biz_name data type is set to varchar and
description data type is set to text

I have altered my table to make both these fields FULL TEXT and phpMyAdmin shows them under the Indexes section indicating that they are full text.

When I perform a query from phpMyAdmin it works but when I try using php as the interface I get errors.

Here is my table structure exported from phpMyAdmin

CREATE TABLE biz_listing (
user_id varchar(20) NOT NULL default '',
biz_id int(10) NOT NULL auto_increment,
biz_name varchar(200) NOT NULL default '',
description text NOT NULL,
address varchar(200) NOT NULL default '',
phone varchar(12) NOT NULL default '',
fax varchar(12) default NULL,
email varchar(100) default NULL,
url varchar(200) default NULL,
PRIMARY KEY (user_id,biz_id),
FULLTEXT KEY biz_name (biz_name,description)
) TYPE=MyISAM;


Here is my search form:


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


and here is the code that processes it.


<?

$database = ""; //removed for security
$user = ""; //removed for security
$pass =""; //removed for security


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

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


$query = "select biz_name from biz_listing where match(biz_name, description) against('$keyword_search')";

$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);

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

?>

I think that it may just be my query but I don't know. This is very annoying and I have been struggling with this for awhile. If anyone can help it would be much appreciated.

Regards

Funky

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingProgramming Tools > Full text search woes


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway