iGuest 3 Report post Posted November 13, 2004 This is a script to search through items quickly... <?php include 'db.php';/* you will need to connect to the database ENTER LOG IN in the included file below :) */$page = $_GET['page'];/*--$page currently refers to the database table name - adjust as neccessary --*/$field1 = '';$field2 = '';/* ADJUST the above 2 values to be 2 columns in the mysql database you want to search */ if(empty($c)) { ?><form action="?page=<? echo $page; ?>&c=1" method=POST><b>Find Results with: </b><br>Any of these words: <input type="text" length=40 name="any"> <br>All of these words: <input type="text" length=40 name="all"> <br>None of these words: <input type="text" length=40 name="none"> <br><input type="submit" value="Search"></form><? } else if($c) { if((!$all) || ($all == "")) { $all = ""; } else { $all = "+(".$all.")"; } if((!$any) || ($any == "")) { $any = ""; } if((!$none) || ($none == "")) { $none = ""; } else { $none = "-(".$none.")"; } $query = " SELECT *, MATCH($field1, $field2) AGAINST ('$all $none $any' IN BOOLEAN MODE) AS score FROM $page WHERE MATCH($field1, $field2) AGAINST ('$all $none $any' IN BOOLEAN MODE)"; $artm1 = MySQL_query($query); if(!$artm1) { echo MySQL_error()."<br>$query<br>"; } echo "<b>Article Matches</b><br>"; if(MySQL_num_rows($artm1) > 0) { echo "<table>"; echo "<tr><td>Score </td><td>$field1 </td><td> $field2</td></tr>"; while($artm2 = MySQL_fetch_array($artm1)) { $val = round($artm2['score'], 3); $val = $val*100; echo "<tr><td>$val</td>"; echo "<td>{$artm2['field1']}</td>"; echo "<td>{$artm2['field2']}</td></tr>";/*ADJUST ABOVE - the 2 lines above assumes the data is coming form columns in the mysql database named field1 and field2 - so adjust to suit you. Also, $val is the score for returned items. The above is essentially the way the script is shown for returned values. */ } echo "</table>"; } else { echo "No Results were found in this category.<br>"; } echo "<br>"; }?> db.php is shown below ENTER LOG IN:<?//set database connection variables$hostname='localhost';$uname='';$password='';$database='';//establish database connection$connect = mysql_connect($hostname,$uname,$password);//display error if connection failsif ($connect==FALSE) { print 'Unable to connect to database: '.mysql_error();} else {//select databasemysql_select_db($database);}?> Share this post Link to post Share on other sites
iGuest 3 Report post Posted December 22, 2004 cool,but how do we add items? Share this post Link to post Share on other sites
iGuest 3 Report post Posted December 24, 2004 you'll need a different script to do that...this is just the search script to search through a table in the db...if your site is big enough to need a search engine, then you should really already have a way of adding items that fits this.Hope it helps Share this post Link to post Share on other sites