Re: Searching a MYSQL DB
| From: | James Holloway | Date: | Wed, 23 May 2001 10:25:37 +0000 |
| Subject: | Re: Searching a MYSQL DB | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-54018@lists.php.net to get a copy of this message | ||
Hey,
Simple solution:
<?
$search = "hammer";
$connection = // Connection to the database details.
$query = @mysql_query("SELECT * FROM table WHERE Name LIKE '%$search%' OR
Description LIKE '%$search%' ORDER BY Name ASC", $connection)
or die (mysql_error());
while($row = mysql_fetch_array($query)) {
$name = $row['Name'];
$description = $row['Description'];
echo "<b>" . stripslashes(htmlentities($name)) .
"</b>\n<BR>\n" .
stripslashes(htmlentities($description)) . "<BR><BR>\n";
}
?>
James.
""YoBro"" <nospam@brochures.co.nz> wrote in message
news:9eg0jl$5ac$1@toye.p.sourceforge.net...
> Hi,
>
> Any ideas, or any code that will allow a search of specific keywords in a
> mysql database.
>
> Feilds in a Table called:
> Name
> Description
>
> What I am after is if somebody types the word 'hammer', then I want it to
> return the results in a list if the word hammer is picked up under the
name
> of description feilds.
>
> Is this easier enough to do?
>
> YoBro
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>