Results 1 to 2 of 2

Thread: Multi field search recordset

  1. #1
    Join Date
    Jan 2008
    Location
    Mansfield, Ohio
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Multi field search recordset

    I am having a problem that I hope someone can help me with? I want to set up a results page that searches about five fields of a table within a database. Basically, I want to setup the recorset so that it catches the word or words from the url and looks within the five fields to see if any of them "contain" the search word.

    Can somebody help me

    thanks in advance

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    1,742
    Thanks
    82
    Thanked 90 Times in 88 Posts

    Default

    Code:
    <?php
    $conn = mysql_connect('localhost', 'mysql_user', 'mysql_password') or die(mysql_error());
    mysql_select_db("mysql_user",$conn)  or die(mysql_error());
    $query = "SELECT * FROM tablename WHERE concat(field1,field2,field3) like \"%search%\" and concat(field1,field2,field3) like\"%term%\"";
    $res = mysql_query($query);
    while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) {
    echo "$row[field4]<br><br>";  
    }
    ?>
    Not sure what you mean when you say:
    Basically, I want to setup the recorset so that it catches the word or words from the url and looks within the five fields to see if any of them "contain" the search word.
    but the above script will search 3 fields in a table so that if the two terms are both found in the three fields selected of a table then it will return the result. The last line just prints off an arbitrary field from the row where the two terms were both found.
    Last edited by james438; 01-23-2008 at 11:45 PM. Reason: typo

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •