Need help to select all the records related to the key word.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • indhuma
    New Member
    • May 2008
    • 3

    Need help to select all the records related to the key word.

    Hi, I want to select all the records against the key word 'thoughts' I wrote the followin code. but i'm getting error!. can you help me?
    [code=php]
    $sqlquery="sele ct * from news where match(day,categ ory,title,artic le)against('tho ughts')";
    $queryresult = mysql_query($sq lquery);
    $row=mysql_fetc h_array($queryr esult);

    echo $row["day"]."<br>";
    echo $row["category"]."<br>";
    echo $row["title"]."<br>";
    echo $row["article"]."<br>";
    [/code]
    Last edited by Atli; May 12 '08, 10:42 AM. Reason: Added [code] tags.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    What error are you getting?

    The MATCH AGAINST syntax is used with full-text searches. Is your table indexed for such a search?

    If not, try using the WHERE LIKE syntax.. somewhat like:
    [code=sql]
    SELECT columns FROM myTable
    WHERE
    column1 LIKE '%keyword%' OR
    column2 LIKE '%keyword%' OR
    column3 LIKE '%keyword%'
    /* etc... */
    [/code]

    P.S.
    I would avoid using the wildcard char (*) in the SELECT query, like you do.
    It will in 99% of cases return a lot more data than needed, which causes extra overhead on the server.
    Specify only the columns you need instead.

    Comment

    Working...