значи проблема е следния. Как да направя да търси примерно по 2 или 3 думи, защото ако не са последователни в текста, казва че няма резултат.. а и как да направя не да оцветява буквите на намерената дума а да е в правоъгълниче заградена което да е оцветено.. ето аз какво съм направил до сега:
http://webjo.no-ip.org/23.1.2007/24.1.2007/123.php
ето го и кога:
http://webjo.no-ip.org/23.1.2007/24.1.2007/123.php
ето го и кога:
Код:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Търсене с маркиране на думи</title>
<meta http-equiv=Content-Type content="text/html; charset=windows-1251" />
<style type="text/css">
body
{
background: #F9F9F7 url('images/a1.gif') repeat-x;
font-size: 11px;
font-family: "trebuchet ms", helvetica, sans-serif;
color: #8C8C73;
line-height: 18px;
}
a
{
color: #FF7800;
text-decoration: underline;
}
a:hover
{
text-decoration: none;
}
</style>
</head>
<body>
<form method="POST" action="123.php">
<table cellpadding="0" cellspacing="0" width="300px" >
<tr>
<td align="right" width="200px"><input class=commentbox type="text" name="Search" size="30"></td>
<td align="right" width="100px"><input class=commentbox type="submit" value="Търси" name="search"></td>
</tr>
</table>
</form>
<?php
$server = "localhost";
$dbusername = "jooorooo";
$dbpassword = "***";
$db_name = "testova";
mysql_connect($server, $dbusername, $dbpassword)or die("Сайтът не може да се свърже към базата данни");
@mysql_select_db($db_name) or die("Грешна база данни");
$broinastranica = 2;
$pageNum = 1;
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
$tarsene = $_POST['Search'];
$trimmed = trim($tarsene);
$trimmed_array = explode(" ",$trimmed);
if ($trimmed == "") {
$resultmsg = "<p>Search Error</p><p>Please enter a search...</p>" ;
}
if (!isset($tarsene)){
$resultmsg = "<p>Search Error</p><p>We don't seem to have a search parameter! </p>" ;
}
foreach ($trimmed_array as $trimm){
$query = "SELECT COUNT(id_news) AS numrows FROM news WHERE title LIKE '%$trimm%' OR newstext LIKE '%$trimm%'";
$result = mysql_query($query) or die('Error, query failed1');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
if ($numrows<1)
{echo "<center><b>Няма намерени резултати за ".$search."</b></center><br><br>";}
$redove = ($pageNum - 1) * $broinastranica;
$querys = " SELECT * FROM news WHERE title LIKE '%$tarsene%' OR newstext LIKE '%$tarsene%' ORDER BY id_news DESC LIMIT $redove, $broinastranica";
$results = mysql_query($querys) or die('Error, query failed2');
while($row = mysql_fetch_array($results))
{
$id_news=$row[id_news];
$title=$row[title];
$cats=$row[cats];
$chas=$row[chas];
$minuti=$row[minuti];
$den=$row[den];
$mesec=$row[mesec];
$godina=$row[godina];
$newstext=$row[newstext];
$titlehigh = preg_replace ( "'($tarsene)'si" , "<font color=#3333CC><b> $tarsene</b></font>" , $row_linkcat[ 'title' ] );
$newstexthigh = preg_replace ( "'($tarsene)'si" , "<font color=#3333CC><b> $tarsene</b></font>" , $row_linkcat[ 'newstext' ] );
foreach($trimmed_array as $trimm){
if($trimm != 'b' ){
$titlehigh = preg_replace( "'($trimm)'si" , "<font color=#3333CC><b> $trimm</b></font>" , $title);
$newstexthigh = preg_replace( "'($trimm)'si" , "<font color=#3333CC><b> $trimm</b></font>" , $newstext);
}
echo "<table width=100% border=1 cellpadding=0 cellspacing=0>
<tr>
<td class=text height=19 background=img/h_gr2.gif> <strong><a href=fullnews.php?id_news=".$id_news.">".$titlehigh."</a></strong></td>
</tr>
<tr>
<td>
<table id=lineLRBs class=nav border=0 cellpadding=0 cellspacing=0 width=100%>
<tr>
<td height=25px id=lineBottom width=33%> Категория: <strong><a href=catview.php?cats=".$cats.">".$cats."</a></strong></td>
<td height=25px id=lineBottom width=33%> </td>
<td height=25px id=lineBottom width=34%> <strong>".$chas.":".$minuti." - ".$den."/".$mesec."/".$godina."</strong></td>
</tr>
<tr>
<td id=lineBottom width=100% colspan=3><div><table cellpadding=5 width=100%>
<tr>
<td width=100%><p align=justify>$newstexthigh</p></td>
</tr>
</table></div></td>
</tr>
</table>";
echo "<br>";
}}}
$maxPage = ceil($numrows/$broinastranica);
$self = $_SERVER['PHP_SELF'];
$nomeranastranici = '';
echo '<center><font face="Tahoma" style="font-size: 8pt">Страници:</font> ';
for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pageNum)
{
$nomeranastranici .= "<font face=\"Tahoma\" style=\"font-size: 8pt\">$page</font>";
}
else
{
$nomeranastranici .= " <font face=\"Tahoma\" style=\"font-size: 8pt\"><a href=\"$self?page=$page\">$page</a> </font>";
}
}
// създаване на ликовете [предишна] [следваща]
// както и линковете [първа] и [последна]
if ($pageNum > 1)
{
$page = $pageNum - 1;
$predishna = "<font face=\"Tahoma\" style=\"font-size: 8pt\"><a href=\"$self?page=$page\">[<<<<<]</a> </font>";
$parva = "<font face=\"Tahoma\" style=\"font-size: 8pt\"><a href=\"$self?page=1\">[първа]</a> </font>";
}
else
{
$predishna = ' ';
$parva = ' ';
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$sledvashta = "<font face=\"Tahoma\" style=\"font-size: 8pt\"><a href=\"$self?page=$page\">[>>>>>]</a> </font>";
$posledna = "<font face=\"Tahoma\" style=\"font-size: 8pt\"><a href=\"$self?page=$maxPage\">[последна]</a></font>";
}
else
{
$sledvashta = ' ';
$posledna = ' ';
}
// показваме всички страници
echo $parva . $predishna . $nomeranastranici . $sledvashta . $posledna;
?>
</body>
</html>