Thanks for replying...Sorry for posting two threads.I wanted to know if newbies can contain forums with problem in database.
I have managed to get the search results.But,I am not able to print a particular field.I want to know the reason.My commands are as follows:
CREATE TABLE mytable(mytable_id int (25) NOT NULL auto_increment,mytable_title varchar(100),mytable_dts varchar(25),mytable_caption tinytext NOT NULL,mytable_full_body text NOT NULL,PRIMARY KEY(mytable_id));
CREATE FULLTEXT INDEX full_index ON mytable(mytable_title,mytable_caption,mytable_full_body);
My code is as follows🙁Sorry for the long post)
<html>
<head><title>Search</title></head>
<body>
<?php
$cnx = mysql_connect('localhost', 'user', 'password') or die ("Could not connect");
mysql_select_db('dbname', $cnx) or die (mysql_error());
function searchForm()
{
$searchwords = (isset($GET['words']) ? htmlspecialchars(stripslashes($REQUEST['words'])) : '');
$normal = (($GET['mode'] == 'normal') ? ' selected="selected"' : '' );
$boolean = (($GET['mode'] == 'boolean') ? ' selected="selected"' : '' );
echo '<form method="get" action="'.$_SERVER['PHP_SELF'].'">';
echo '<input type="hidden" name="cmd" value="search" />';
echo 'Search for: <input type="text" name="words" value="'.$searchwords.'" /> ';
echo 'Mode: ';
echo '<select name="mode">';
echo '<option value="normal"'.$normal.'>Normal</option>';
echo '<option value="boolean"'.$boolean.'>Boolean</option>';
echo '</select> ';
echo '<input type="submit" value="Search" />';
echo '</form>';
}
// Create the navigation switch
$cmd = (isset($GET['cmd']) ? $GET['cmd'] : '');
switch($cmd)
{
default:
echo '<h1>Search Database!</h1>';
searchForm();
break;
case "search":
searchForm();
echo '<h3>Search Results:</h3><br />';
$searchstring = mysql_escape_string($_GET['words']);
switch($_GET['mode'])
{
case "normal":
$sql = "SELECT mytable_id, mytable_title, mytable_caption, mytable_dts,
MATCH(mytable_title, mytable_caption, mytable_full_body)
AGAINST ('$searchstring') AS score FROM mytable
WHERE MATCH(mytable_title, mytable_caption, mytable_full_body)
AGAINST ('$searchstring') ORDER BY score DESC";
break;
case "boolean":
$sql = "SELECT mytable_id, mytable_title, mytable_caption, mytable_dts,
MATCH(mytable_title, mytable_caption, mytable_full_body)
AGAINST ('$searchstring IN BOOLEAN MODE') AS score FROM mytable
WHERE MATCH(mytable_title, mytable_caption, mytable_full_body)
AGAINST ('$searchstring IN BOOLEAN MODE') ORDER BY score DESC";
break;
}
// echo $sql;
$result = mysql_query($sql) or die (mysql_error());
while($row = mysql_fetch_object($result))
{
echo '<strong>Year: '.stripslashes(htmlspecialchars($row->mytable_title)).'</strong><br />';
#echo 'Score:'. number_format($row->score, 1).' Title: '.date('m/d/y', $row->mytable_full_body).'<br />';
echo '<strong>Author:<p>'.stripslashes(htmlspecialchars($row->mytable_caption)).'</p>';
echo '<strong>Title:<p>'.stripslashes(htmlspecialchars($row->mytable_full_body)).'</p>';
echo '<hr size="1" />';
}
break;
}
mysql_close($cnx);
?>
</body>
</html>
I am not able to understand why I am not able to print mytable_full_body.Please help me out.