integrating a full text search with php.

Discussion in 'Databases' started by lazarus, Mar 29, 2006.

  1. #1
    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";
    ?> 
    PHP:



    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
     
    lazarus, Mar 29, 2006 IP
  2. vishwaa

    vishwaa Well-Known Member

    Messages:
    271
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    138
    #2
    $result = mysql_query($query) or die ("Query failed");

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

    I believe it would be the same "Can't find FULLTEXT index matching the column list" error.
     
    vishwaa, Mar 29, 2006 IP
  3. lazarus

    lazarus Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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 29, 2006 IP
  4. lazarus

    lazarus Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    
    <?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";
    ?>  
    PHP:


    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.
     
    lazarus, Mar 30, 2006 IP
  5. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Install Orca search by Brian Huisman instead. It has loads of neat functions and is fast as Google.
     
    T0PS3O, Mar 30, 2006 IP
  6. lazarus

    lazarus Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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.
     
    lazarus, Mar 30, 2006 IP