require( "functions.php" );
displayHeader( "Keyword Search" );
echo "
Поиск по ключевому слову
";
if( isset( $keyword ) )
{
$keyword = trim( $keyword );
if( strlen( $keyword ) == 1 ) $keyword = "";
if( $keyword != "" )
{
dbConnect();
$result = mysql_query( "SELECT rootID, parentID, topic, name, time, msg FROM $forum_table WHERE
topic LIKE '%$keyword%' || msg LIKE '%$keyword%' || name LIKE '%$keyword%' ORDER BY time DESC" );
$foundNum = mysql_num_rows( $result );
$keyword = stripslashes( $keyword );
echo "
Найдено $foundNum по ключу '$keyword' |
";
$i = 1;
while( $row = mysql_fetch_array( $result ) )
{
if( $row[ 'parentID' ] == 0 ) $id = "{$row[ 'rootID' ]},{$row[ 'rootID' ]}";
else $id = findRootID( $row[ 'parentID' ] ) . ",{$row[ 'rootID' ]}";
$row[ 'topic' ] = eregi_replace( $keyword, "$keyword", $row[ 'topic' ] );
$row[ 'msg' ] = eregi_replace( $keyword, "$keyword", $row[ 'msg' ] );
$row[ 'name' ] = eregi_replace( $keyword, "$keyword", $row[ 'name' ] );
echo "
$i. |
{$row[ 'topic' ]} | От: {$row[ 'name' ]} [" .
strftime( "%c", $row[ 'time' ] ) . "] |
|
{$row[ 'msg' ]} |
";
$i++;
}
echo "
";
}
}
echo "
[Список дискуссий] [Назад]
";
displayFooter();
function findRootID( $parentID )
{
global $forum_table;
$result = mysql_query( "SELECT rootID, parentID FROM $forum_table WHERE rootID=$parentID" );
if( !$result ) {
return $parentID;
exit;
}
$row = mysql_fetch_row( $result );
findRootID( $row[ 1 ] );
return $row[ 0 ];
}
?>