Full-text search
Posted: Mon Jun 16, 2008 1:25 pm
Hi All
I wonder if you could help me I'm trying to write a programm for Full-text search but I can not seem to get the query right. error says it can not connect to databse. Here is my code
On same script if I use different query it works fine for example if I take off MATCH and AGAINST and just leave it to show all ItemName it works.
Zed
I wonder if you could help me I'm trying to write a programm for Full-text search but I can not seem to get the query right. error says it can not connect to databse. Here is my code
Code: Select all
<?php
$database = "sampledb";
$user = "xxxxxxxx";
$pass = "xxxxxx";
$hostname = "localhost";
$table = "itemtb";
$db = mysql_connect("$hostname", "$user","$pass");
mysql_select_db("$database");
// If the form has been submitted with supplied keywords
if (isset($_POST['keywords'])) {
// Connect to server and select database
$keywords = $_POST['keywords'];
// Create the query
$query= "SELECT ItemName FROM itemtb WHERE MATCH(ItemName) against(`$keywords`)";
$result = mysql_query($query)
or die ("Couldn't execute query for collecting your data.");
?>
<TABLE BORDER=0 WIDTH=90% CELLSPACING=3 CELLPADDING=3 ALIGN=CENTER bgcolor="#99CC99">
<TR ALIGN=CENTER bgcolor="#CCFF66">
<td><font color=red><b>Item name</font></TD>
</tr>
<?
while ($row = mysql_fetch_array($result)) {
extract($row);
echo "<tr align=center>
<td>" . $row['ItemName'] . "</td>
</tr>";
}
?></table><?
}
?>
<p>
<form name="action" id="action" method="post" action="<?=$_SERVER['PHP_SELF']?>">
Keywords:<br />
<input type="text" name="keywords" size="20" maxlength="40" value="" /><br />
<input type="submit" value="Search!">
</form>
Zed