Cheap Books - IKA Processing Equipment - Debt Consolidation - Debt Consolidation - Debt

PDA

View Full Version : integrating a full text search with php.


lazarus
Mar 29th 2006, 1:52 pm
i cant seem to get the full text search to work can someone assist me. i know the last time vishwaa and a few others gave me alot of help and i was able to dolve one problem.. now im moving onto the php coding part and im have a problem with the query it keeps saying that the query failed. i didnt add the wildcard yet to search for text yet. so heres the cod.e thank you very much in advance.



<?php
$db = mysql_connect("localhost","*****","*******") or die("Problem connecting");
mysql_select_db("testDB") or die("Problem selecting database");
$query = "SELECT * FROM indexing WHERE MATCH(companyName, address, city, state, country, phoneNumber, contact1, sic, faxNumber, keyWords) AGAINST('Amery')";
$result = mysql_query($query) or die ("Query failed");
//let's get the number of rows in our result so we can use it in a for loop
$numofrows = mysql_num_rows($result);
?>

<?php
echo "<TABLE BORDER=\"1\">\n";
echo "<TR bgcolor=\"lightblue\"><TD><center>COMPANY NAME</center></TD><TD>ADDRESS</TD><TD>COUNTRY</TD></TR>\n";
for($i = 0; $i < $numofrows; $i++) {
$row = mysql_fetch_array($result); //get a row from our result set
if($i % 2) { //this means if there is a remainder
echo "<TR bgcolor=\"yellow\">\n";
} else { //if there isn't a remainder we will do the else
echo "<TR bgcolor=\"white\">\n";
}
echo "<TD>".$row['companyName']."</TD><TD>".$row['address']."</TD><TD>".$row['country']."</TD>\n";
echo "</TR>\n";
}
//now let's close the table and be done with it
echo "</TABLE>\n";
?>




is it possible because i didnt finish the table part at the bottom of the script? because i was in a hurry to test it out. im off to college now but i will keep checking . and again thanks

vishwaa
Mar 29th 2006, 2:15 pm
$result = mysql_query($query) or die ("Query failed");

replace the above line with the code below and post the error message

$result = mysql_query($query,$db) or die("Error: ".mysql_error());

I believe it would be the same "Can't find FULLTEXT index matching the column list" error.

lazarus
Mar 29th 2006, 6:17 pm
Error: Unknown column 'contact1' in 'where clause'

i got the above error but when i try a select query to shoq all the fields it works soon as i change to this type of query like the where match it gives the above error.

lazarus
Mar 30th 2006, 7:53 am
<?php





$db = mysql_connect("localhost","****","*****") or die("Problem connecting");
mysql_select_db("contacts") or die("Problem selecting database");
$query = "SELECT * FROM contacts WHERE MATCH(companyName, address, city, state, country, phoneNumber, contact1, sic, faxNumber, keyWords) AGAINST('Amery')";
$result = mysql_query($query,$db) or die("Error: ".mysql_error());
//let's get the number of rows in our result so we can use it in a for loop
$numofrows = mysql_num_rows($result);
?>

<?php
echo "<TABLE BORDER=\"1\">\n";
echo "<TR bgcolor=\"lightblue\"><TD><center>COMPANY NAME</center></TD><TD>ADDRESS</TD><TD>CITY</TD><TD>STATE</TD><TD>COUNTRY</TD><TD>PHONE NUMBER</TD><TD>CONTACT</TD><TD>SIC</TD><TD>FAX NUMBER</TD></TR>\n";
for($i = 0; $i < $numofrows; $i++) {
$row = mysql_fetch_array($result); //get a row from our result set
if($i % 2) { //this means if there is a remainder
echo "<TR bgcolor=\"yellow\">\n";
} else { //if there isn't a remainder we will do the else
echo "<TR bgcolor=\"white\">\n";
}
echo "<TD>".$row['companyName']."</TD><TD>".$row['address']."</TD><TD>".$row['city']."</TD><TD>".$row['state']."</TD><TD>".$row['country']."</TD><TD>".$row['phoneNumber']."</TD><TD>".$row['contact1']."</TD><TD>".$row['sic']."</TD><TD>".$row['faxNumber']."</TD>\n";
echo "</TR>\n";
}
//now let's close the table and be done with it
echo "</TABLE>\n";
?>



can someone suggest how i can convert this into like a text search for a website like where i put in some text and it will search for that string.

T0PS3O
Mar 30th 2006, 7:56 am
Install Orca search by Brian Huisman instead. It has loads of neat functions and is fast as Google.

lazarus
Mar 30th 2006, 8:54 am
ok after alot of searching and manipulation of my own code. i was lazy to write it but i finally got around to writing it. i got the stuff. thanks everyone.

thanks tops will look into that too.