BUX Posted November 7, 2009 Share Posted November 7, 2009 I will post here the code of a page which lists items found in one of my dbs. I would like to enter e search feature. I have inserted the form and set a variable for the entered word, also tried following a few tutorials but it got a bit complicated. I would like the page to display all the items at first and the searched items if a search is done. Could anyone help me recode this? Thanks in advance. <html> <TITLE>Data List Page</TITLE> <body> <?php $username="XXXXX"; $password="XXXXX"; $database="XXXXX"; $var = @$_GET['word'] ; $trimmed = trim($var); mysql_connect('192.168.0.1',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM filez ORDER BY name ASC"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <table width="835" border="1" align="center"> <tr> <th width="311"><font face="Arial, Helvetica, sans-serif">Name</font></th> <th width="417"><font face="Arial, Helvetica, sans-serif">File</font></th> <th width="85"><font face="Arial, Helvetica, sans-serif">Download</font></th> </tr> </table> <form name="form" action="search.php" method="get"> <table width="835" border="0" align="center"> <tr bgcolor="#FFFFFF"> <td width="146" ><input type="text" name="word" /></td> <td width="679"><input type="submit" name="submit" value="Search" /></td> </tr> </table> </form> <?php $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"name"); $f2=mysql_result($result,$i,"file"); ?> <table width="835" border="0" align="center"> <tr bgcolor="#66FFFF"> <td width="311"><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td> <td width="417"><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td> <td width="85"><font face="Arial, Helvetica, sans-serif"><a href="http://www.inducedvision.com/XXXX/<?php echo $f2; ?>" title="DOWNLOAD FILE" target="_self">Link</a></font></td> </tr> </table> <?php $i++; } ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
PHPiSean Posted November 7, 2009 Share Posted November 7, 2009 is this http://www.designplace.org/scripts.php?page=1&c_id=25 what you were looking for? Quote Link to comment Share on other sites More sharing options...
BUX Posted November 7, 2009 Author Share Posted November 7, 2009 Thank you for the fast reply, indeed this is a tutorial showing a search engine, but it seemns quite complicated for me to blend it into my page (i have read it b4), i have a found an 'easier' version of a search engine here http://www.spoono.com/php/tutorials/tutorial.php?id=12 but although this includes less code im having trouble inserting it into my page, and mainly having the page display all the items at first and the searched ones after a search is done. Am I supposed to enter an if loop containing the html which displays the fields, corresponding to the $search or sometihng like that? here is my updated code <html> <TITLE>Data List Page</TITLE> <body> <?php $username="XXXXX"; $password="XXXXX"; $database="XXXXX"; $search=@$_GET['word'] ; mysql_connect('192.168.0.1',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM filez ORDER BY name ASC"; $result=mysql_query($query); $resultsearch=mysql_query("SELECT * FROM filez WHERE name LIKE '%$search%' ORDER BY name ASC"); $num=mysql_numrows($result); mysql_close(); ?> <table width="835" border="1" align="center"> <tr> <th width="311"><font face="Arial, Helvetica, sans-serif">Name</font></th> <th width="417"><font face="Arial, Helvetica, sans-serif">File</font></th> <th width="85"><font face="Arial, Helvetica, sans-serif">Download</font></th> </tr> </table> <form action="search.php" method="gett"> <table width="835" border="0" align="center"> <tr bgcolor="#FFFFFF"> <td width="146" ><input type="text" name="word" /></td> <td width="679"><input type="submit" name="submit" value="Search" /></td> </tr> </table> </form> <?php $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"name"); $f2=mysql_result($result,$i,"file"); $f3=mysql_result($resultsearch,$i,"name"); $f4=mysql_result($resultsearch,$i,"file"); ?> <table width="835" border="0" align="center"> <tr bgcolor="#66FFFF"> <td width="311"><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td> <td width="417"><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td> <td width="85"><font face="Arial, Helvetica, sans-serif"><a href="http://www.inducedvision.com/XXXX/<?php echo $f2; ?>" title="DOWNLOAD FILE" target="_self">Link</a></font></td> </tr> </table> <?php $i++; } ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
PHPiSean Posted November 7, 2009 Share Posted November 7, 2009 the loop in the link I showed you is verifying how many results there is going to be. Without the loop it would display everything in your database. To display a close search, you might want to try and create your own boolean system that displays keywords in the text and compare it to the database. Mentioning the closest results first. I personally cannot recall a boolean operator function, but I'm sure there is one. Quote Link to comment Share on other sites More sharing options...
PHPiSean Posted November 7, 2009 Share Posted November 7, 2009 Sorry for double posting, but if you used the tutorial you found and just change the database name to match yours, then there is your MySQL search Quote Link to comment Share on other sites More sharing options...
BUX Posted November 7, 2009 Author Share Posted November 7, 2009 If anyone could post a fixed version of my code i would really apprecite it. Thanks Quote Link to comment Share on other sites More sharing options...
BUX Posted November 8, 2009 Author Share Posted November 8, 2009 bump Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.