"nagendra prasad" <nagendra802000@xxxxxxxxx> wrote in message news:AANLkTinESp1vyn3dO_UBcaX9LtlHF5YQduwE24IamckX@xxxxxxxxxxxxxxxxx > 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: > > > > <?php > > > //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 "<br><table align='center'><tr><td><sup>†</sup><font > face='sana-serif' size='6'><font color='blue'><b><sup><a href=' > http://localhost/searchengine/' style='text-decoration: > none'>MP3dom</a></sup></b></b></font><font face='sana-serif' > size='3'><sup>™</sup></td><td><sup><form action='search.php' > method='GET'><input type='text' onclick=value='' size='50' name='search' > value='$search'> <input type='submit' name='submit' > value='Search'></form></td></tr></table> <table bgcolor='#0000FF' > width='100%' height='1px'><br /></table><table bgcolor='#f0f7f9' > width='100%' height='10px'><tr><td><div align='right'><b>Must be greater > then 3 chars</b></div></td></tr></table><p></sup>"; > else > { > echo "<br><table align='center'><tr><td>†<font face='sana-serif' > size='6'><font color='blue'><b><a href='http://localhost/searchengine/' > style='text-decoration: none'>MP3dom</a></b></b></font><font > face='sana-serif' size='3'><sup>™</sup></td><td><sub><form > action='search.php' method='GET'><input type='text' onclick=value='' > size='50' name='search' value='$search'><input type='submit' name='submit' > value='Search'></form></td></tr></table></sub>"; > > //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 "<table bgcolor='#F1EDC2' width='100%' height='1px'><br > /></table><table bgcolor='#f0f7f9' width='100%' height='10px'><tr><td><div > align='right'>No results found for > <b>$search</b></div></td></tr></table><p>"; > else > { > echo "<table bgcolor='#F1EDC2' width='100%' height='1px'><br > /></table><table bgcolor='#f0f7f9' width='100%' height='10px'><tr><td><div > align='right'>Showing 1-30 of <b>$foundnum</b> results found for > <b>$search.</b></div></td></tr></table><p>"; > > > > > > > > print '<table bgcolor="#F1EDC2" width="700" height="30" border="0" > align="center" >'; > print '<tr>'; > > print '<td width="100" nowrap="nowrap"><strong>Artist</strong></td>'; > print '<td width="250" nowrap="nowrap"><strong>Song > Name</strong></td>'; > print '<td width="50" nowrap="nowrap"><strong>Movie > Date</strong></td>'; > print '<td width="50" nowrap="nowrap"><strong>Size</strong></td>'; > > print '</tr>'; > 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 '<table width="700" height="30" border="0" align="center">'; > > } > > > print '<?php do { ?>'; > print '<tr bgcolor="' . $rowColor . '">'; > > print '<td nowrap="nowrap" width="100">'.'<font color=:blue" > size=2>'."$type".'</td>'; > //print '<td nowrap="nowrap" width="250">'.'<font size=2>'."<a > herf='$url'>$name".'</td>'; > > print '<td nowrap="nowrap" width="250">'.'<font color="blue" > size=2>'."<a href='download.php?url=$url'>$name".'</font></td>'; > > > print '<td nowrap="nowrap" width="100" align="center">'.'<font > size=2>'."$date ".'</td>'; > print '<td nowrap="nowrap" width="50">'.'<font size=2>'."$size > ".'</td>'; > print '<td nowrap="nowrap" width="25">'.'<font size=2>'."$se > ".'</td>'; > print '<td nowrap="nowrap" width="25">'.'<font size=2>'."$le > ".'</td>'; > print '</tr>'; > > > > print '</table>'; > print '</body>'; > print '</html>'; > > } > ?> > > > <table width='100%'> > <tr> > <td> > <div align="center"> > <br><br> > <?php > if (!$s<=0) > echo "<a href='search.php?search=$search&s=$prev'>Prev</a>"; > > $i =1; > for ($x=0;$x<$foundnum;$x=$x+$e) > { > > > echo " <a href='search.php?search=$search&s=$x'>$i</a> "; > > > $i++; > > > } > > if ($s<$foundnum-$e) > echo "<a href='search.php?search=$search&s=$next'>Next</a>"; > > } > } > > > ?> > </div> > </td> > </tr> > </table> > > > *************************************************************************************************** > > Also, the above code is giving me the below errors: > > *Notice*: Undefined index: s in *C:\wamp\www\searchengine\search.php* on > line *11 > **Notice*: Undefined variable: x in *C:\wamp\www\searchengine\search.php* > on > line *46* > > *Notice*: Undefined variable: construct in * > C:\wamp\www\searchengine\search.php* on line *48 > > > ****************************************************************************************************************** > > Please help me with this. > > Best, > Guru. > > * > Hi, use fulltext search: http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html Br Tanel -- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php