can some one please help me adapt my script so that i can search for multiple words within my database,
my keywords feild looks something like this....
[code=php]
Big Teddie Bear Collection Tiny Small Soft
[/code]
At the moment if i search for the word "teddie" i will get "teddie" and if i search for "teddie bear" i will get "teddie bear", because in the keywords feild in the database "teddie" and "bear" are next to each other. but if i search for soft teddie i would get no results please help.
this is my script....
[code=php]
<?php
function search() {
// Get the search variable from URL
$var = ucwords(strtolo wer(@$_GET['q']));
$trimmed = trim($var); //trim space from the stored variable
// rows to return
$limit=15;
$s = trim(@$_GET['s']);
// check for an empty string and display a message.
if ($trimmed == "")
{
}
mysql_connect(" localhost","use rname","pass"); //(host, username, password)
mysql_select_db ("myphotos") or die("Unable to select database"); //select which database we're using
// Build SQL Query
$query = "SELECT id, description, tn_src, src, lens, titles FROM dogs WHERE CONCAT(keywords , ' ', id, description, lens, camera, copyright, titles, Price) LIKE \"%$trimmed% \"
ORDER BY id DESC";
$numresults=mys ql_query($query );
$numrows=mysql_ num_rows($numre sults);
if ($numrows == 0)
{
$q = "SELECT titles, description, tn_src, src, id FROM dogs ORDER BY RAND() LIMIT 15";
$r = mysql_query($q) or die("Couldn't execute query");
[/code]
my keywords feild looks something like this....
[code=php]
Big Teddie Bear Collection Tiny Small Soft
[/code]
At the moment if i search for the word "teddie" i will get "teddie" and if i search for "teddie bear" i will get "teddie bear", because in the keywords feild in the database "teddie" and "bear" are next to each other. but if i search for soft teddie i would get no results please help.
this is my script....
[code=php]
<?php
function search() {
// Get the search variable from URL
$var = ucwords(strtolo wer(@$_GET['q']));
$trimmed = trim($var); //trim space from the stored variable
// rows to return
$limit=15;
$s = trim(@$_GET['s']);
// check for an empty string and display a message.
if ($trimmed == "")
{
}
mysql_connect(" localhost","use rname","pass"); //(host, username, password)
mysql_select_db ("myphotos") or die("Unable to select database"); //select which database we're using
// Build SQL Query
$query = "SELECT id, description, tn_src, src, lens, titles FROM dogs WHERE CONCAT(keywords , ' ', id, description, lens, camera, copyright, titles, Price) LIKE \"%$trimmed% \"
ORDER BY id DESC";
$numresults=mys ql_query($query );
$numrows=mysql_ num_rows($numre sults);
if ($numrows == 0)
{
$q = "SELECT titles, description, tn_src, src, id FROM dogs ORDER BY RAND() LIMIT 15";
$r = mysql_query($q) or die("Couldn't execute query");
[/code]
Comment