tried.. but i dunt get the results.. shall post my codes here.. Please help. Thanks. Not too sure where to place the codes. One radio button to search for Title, and the other for Keyword. Cos' so far, im able to do only a basic keyword search. CONFUSED.
current search :
// Get the search variable from URL
$var = @$_GET['document'] ;
//trim whitespace from the stored variable
$trimmed = trim($var);
//separate key-phrases into keywords
$trimmed_array = explode(" ",$trimmed);
// check for an empty string and display a message.
//if ($trimmed == "") {
//$resultmsg = "<p>Search Error:</p><p>Please enter a search...</p>" ;
// }
// check for a search parameter
if (!isset($var)){
$resultmsg = "" ;
}
// Build SQL Query for each keyword entered
foreach ($trimmed_array as $trimm){
// EDIT HERE and specify your table and field names for the SQL query
$query = "SELECT * FROM Document WHERE DocNo like \"%$trimm%\" OR Title LIKE \"%$trimm%\"OR DocType like \"%$trimm%\" OR DocDescription like \"%$trimm%\" OR AircraftType like \"%$trimm%\" ORDER BY Title DESC" ;
// Execute the query to get number of rows that contain search kewords
$numresults=mysql_query ($query);
$row_num_links_main =mysql_num_rows ($numresults);
// next determine if 's' has been passed to script, if not use 0.
// 's' is a variable that gets set as we navigate the search result pages.
if (empty($_GET['s']))
{
$s=0;
}elseif (is_numeric($_GET['s'])){
$s = $_GET['s'];
}//end if
// now let's get results.
$query .= " LIMIT $s,$limit" ;
$numresults = mysql_query ($query) or die ( "Could not execute query" );
$row= mysql_fetch_array ($numresults);
//store record id of every item that contains the keyword in the array we need to do this to avoid display of duplicate search result.
do{
$adid_array[] = $row[ 'Docid' ];
}while( $row= mysql_fetch_array($numresults));
} //end foreach
$row_set_num = null;
if($row_num_links_main == 0 && $row_set_num == 0){
$resultmsg = "<p>Search results for:<b><br> ". $trimmed."</b></p><p>Sorry, your search returned zero results</p>" ;
}
//delete duplicate record id's from the array. To do this we will use array_unique function
$tmparr = array_unique($adid_array);
$i=0;
$newarr = isSet($_POST['Search']) ? $_REQUEST['Search'] : '';
foreach ($tmparr as $v) {
$newarr .= "'" . $v . "',"; //turn newarr into a comma separated string good for an in clause in a query
}
$newarr = substr($newarr,0,strlen($newarr)-1); //remove the trailing comma
form :
<table width="73%" height="459" border="1" bordercolor="#0099FF">
<tr>
<td><input name="Report" type="submit" id="Report2" value="Report"> <input name="Review" type="submit" id="Review" value="Review">
<input name="Logout" type="submit" id="Logout2" value="Logout">
</td>
</tr>
<tr>
<td><table width="91%" height="50" border="1" align="center">
<tr>
<td height="80">
<p align="center"> </p>
<p align="center"><strong>Search for Document: </strong> <strong>
<input type "text" name="document" />
<input type="submit" name="Submit" value="Search" />
</strong> </p>
<p align="center">
<input name="rb_Select" type="radio" value="Title">Title
<input name="rb_Select" type="radio" value="Keyword" checked>Keyword
<input name="cb_phrase" type="checkbox" id="cb_phrase" value="cb_phrase">By phrase
<br>
</p>
<br>
</p>
</tr></table>
<?php
// display what the person searched for.
if( isset ($resultmsg)){
echo $resultmsg;
exit();
}else{
echo "Search results for:<b><br>" . $var . "</b><br>";
}
//end highlight
$cntr = 1 ; //counter for the table columns
echo "<table width=100% align=center border=1><tr>
<td align=center bgcolor=#0099FF>DocNo</td>
<td align=center bgcolor=#0099FF>Title</td>
<td align=center bgcolor=#0099FF>DocType</td>
<td align=center bgcolor=#0099FF>DocDescription</td>
</tr><tr>";
// EDIT HERE and specify your table and field names for the SQL query
$query_value = "SELECT * FROM document WHERE docid in ($newarr)";
$num_value=mysql_query ($query_value);
while ($row_linkcat= mysql_fetch_array ($num_value))
{
$row_num_links= mysql_num_rows ($num_value);
//$DocNo = $row_linkcat[ '1' ];
//$Title = $row_linkcat[ '2' ];
//$DocType = $row_linkcat[ '3' ];
//$DocDescription = $row_linkcat[ '4' ];
$row_num_links= mysql_num_rows ($num_value);
//now let's make the keywords bold. To do that we will use preg_replace function.
//Replace field
$Title = preg_replace ( "'($var)'si" , "<b>$trimm</b>" , $row_linkcat[ '1' ] );
$DocNo = preg_replace ( "'($var)'si" , "<b>$trimm</b>" , $row_linkcat[ '2' ] );
$DocType = preg_replace ( "'($var)'si" , "<b>$trimm</b>" , $row_linkcat[ '3' ] );
$DocDescription = preg_replace ( "'($var)'si" , "<b>$trimm</b>" , $row_linkcat[ '4' ] );
//if there are 7 cols, write the <tr> tag and reset the counter
if ($cntr == 2)
{
echo "</tr><tr>";
$cntr =1;
}
echo "
<td>$DocNo </td>
<td>$Title </td>
<td>$DocType </td>
<td>$DocDescription </td>
";
$cntr++; //increment the counter
}//end while
echo "</tr></table>";
?>