|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 <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 |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Programming Tools > Full text search woes |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|