I´m using fulltext to search in my mysql db. It´s working very well. but the results description r not very interesting for the user. i´m sure this can be changed.
Have a look at this query:
mysql_select_db($database_obs, $obs);
$query_noticias = "SELECT * FROM maacdb.noticias WHERE activo = '1' AND MATCH (titulo, texto) AGAINST ('$q')";
$noticias = mysql_query($query_noticias, $obs);
$row_noticias = mysql_fetch_assoc($noticias);
$totalRows_noticias = mysql_num_rows($noticias);
//echo mysql_errno() . ": " . mysql_error(). "\n";
then print the results:
<? if (mysql_num_rows($noticias) > 0) { ?>
<p><strong><?php echo mysql_num_rows($noticias) ?> ocorrência(s) nas notícias:</strong>
<?php do { ?>
<P><STRONG><FONT SIZE="2"><a HREF="?pagina=noticia&dest=1&q=<? echo $q; ?>&idn=<?php echo $row_noticias['id']; ?>"><?php $textoz = eregi_replace("$q","<font color=\"red\">$q</font>",$row_noticias['titulo']); echo $textoz; ?></a> </FONT></STRONG><BR>
<?php
$texto = substr($row_noticias['texto'],0,150);
$texto = eregi_replace("$q","<font color=red><u>$q</u></font>",$texto);
echo $texto; ?>
...... </P>
<?php } while ($row_noticias = mysql_fetch_assoc($noticias)); } ?>
The best I can do is to limit the text for the first 150 characters using substr, and underline in the first 150 characters those words matching the query.
But sometimes to words matching the query are below. :mad:
How do i print that part of text where the matching words are ?
😕