Help needed in searching a sentence in the code
am 26.05.2010 16:20:31 von Nagendra Prasad--000e0cd13bba2b825304877ffb03
Content-Type: text/plain; charset=ISO-8859-1
Hi All,
I have this code where user can search a song or the entire song title. It
looks like when a user search a single word its searching and giving the
proper results. However if the user wants to search the entire sentence its
not giving the proper results. For example let say I have searched for the
MJ's song "Earth Song", its giving me the proper results. However if I am
searching for the MJ's " Why You Wanna Trip On Me", its not giving me the
proper results. Below is the code:
//get data
$button = $_GET['submit'];
$search = $_GET['search'];
$s = 0;
$s = $_GET['s'];
if (!$s)
$s = 0;
$i = 0;
$e = 30; // Just change to how many results you want per page
$next = $s + $e;
$prev = $s - $e;
if (strlen($search)<=2)
echo "
† face='sana-serif' size='6'>MP3dom size='3'>™ | method='GET'> value='$search'> value='Search'> |
then 3 chars
";
else
{
echo "
† size='6'> style='text-decoration: none'>MP3dom face='sana-serif' size='3'>™ | action='search.php' method='GET'> size='50' name='search' value='$search'> value='Search'> |
//connect to database
mysql_connect("localhost","root","");
mysql_select_db("mp3");
//explode out search term
$search_exploded = explode(" ",$search);
foreach($search_exploded as $search_each)
{
//construct query
$x++;
if ($x==1)
$construct .= "name LIKE '%$search_each%'";
else
$construct .= " OR name LIKE '%$search_each%'";
}
//echo outconstruct
$constructx = "SELECT * FROM data WHERE $construct";
$construct = "SELECT * FROM data WHERE $construct LIMIT $s,$e ";
$run = mysql_query($constructx);
$foundnum = mysql_num_rows($run);
$run_two = mysql_query("$construct");
if ($foundnum==0)
echo "
align='right'>No results found for $search |
";
else
{
echo "
align='right'>Showing 1-30 of $foundnum results found for $search. |
";
print '
print '
print '
print '
Name
print '
Date
print '
print '
while ($runrows = mysql_fetch_assoc($run_two))
{
//get data
$type = $runrows['artist'];
$date = $runrows['date'];
$name = $runrows['name'];
$size = $runrows['size'];
foreach ($runrows as $row)
{
if ($i % 2 != 0) # An odd row
$rowColor = "#EBECE4";
else # An even row
$rowColor = "#FEF1E9";
print '
'.' size=2>'."$type".' | ';'.''." herf='$url'>$name".' | ';'.' size=2>'."$name".' | ';'.' size=2>'."$date ".' | ';'.''."$size ".' | ';'.''."$se ".' | ';'.''."$le ".' | ';
print '