Code To Search Single Keyword Only

Hi,

I have code which queries an exact word and works fine but I am now trying to change it so picks out a single keyword within a sentence and I have got into a twizzle over it. Any ideas please?

So if the query is ‘red’ it will display everything from ‘large red widgets’. Currently I have reading ‘large red widgets’ only.

<?php

$name = mysql_real_escape_string "%($_GET['name'])%";


$query = mysql_query("SELECT `name`, `product_id`, `rrp`, `discount`, `image_link`
                                 FROM `productdbase`
                                 JOIN `furniture_groups`
                                 ON (`furniture_groups`.`long_name` = `productdbase`.`furniture_group`)

                                 LIKE is exact. LIKE + %'name'% `name` = 'name'  LIMIT 15");


 while ($query_row = mysql_fetch_assoc($query)) {

?>

Give this’n a go:

<?php
$name = mysql_real_escape_string($_GET['name']);
$query = mysql_query("
    SELECT name, product_id, rrp, discount, image_link
        FROM productdbase p
        INNER JOIN furniture_groups f
            ON
                f.long_name = p.furniture_group
        WHERE
            name LIKE '%{$name}%'
    LIMIT 15
");
while ($query_row = mysql_fetch_assoc($query)) {

Is this a question also about how to highlight the search term in a sentence, I wonder?

So if the query is ‘red’ it will display everything from ‘large red widgets’. Currently I have reading ‘large red widgets’ only.

If so, please clarify what you mean by showing us a better sample of what you have in your db, what the search term will likely be, and what you want the results page to look like.

Sorted, thanks mate.

I was just looking to query a single word instead of a full keyword. Thanks for that.