<?
$query = "SELECT * FROM mess 
WHERE ".$lok."
ORDER BY id_mess DESC";	

//echo $query.'<br>';

$maxRows_Recordset1=20;
$pn = 0;
if (isset($_GET['pn'])) 
 {
  $pn = $_GET['pn'];
 }
$startRow_Recordset1 = $pn * $maxRows_Recordset1;

$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query, $startRow_Recordset1, $maxRows_Recordset1);

$Recordset1 = mysql_query($query_limit_Recordset1, $connect) or die(mysql_error());
$row_Recordset1 = mysql_fetch_array($Recordset1);

$all_Recordset1 = mysql_query($query);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
//echo '<p>'.$totalRows_Recordset1.'</p>';
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

do { 
	if (isset ($row_Recordset1['id_mess'])) 
		{ 
		if($row_Recordset1['komu']==$_SESSION['ID_P'][1] || $row_Recordset1['komu']==-1)
			{
			echo '<table width=100%><tr><td class=tb2>';
			echo '<font color=green>'.date($date_format_site2, strtotime($row_Recordset1['data'])).'</font>';
			if($row_Recordset1['ot_kogo']==0) $font='color=#8A0000'; else $font='';
			echo '<br><font '.$font.'>От кого: <b>'.$row_Recordset1['autor'].'</b></font>';
			echo '<br>'.str_replace("\n","<br>",trim($row_Recordset1['mess']));
			echo '</table><p>';
			}
		elseif($row_Recordset1['ot_kogo']==$_SESSION['ID_P'][1])
			{
			echo '<table width=100%><tr><td class=tb2>';
			echo '<font color=green>'.date($date_format_site2, strtotime($row_Recordset1['data'])).'</font>';
			if($row_Recordset1['komu']==0) $font='color=#8A0000'; else $font='';
			echo '<br><font '.$font.'>Кому: <b>'.$row_Recordset1['autor_komu'].'</b></font>';
			echo '<br><em>'.str_replace("\n","<br>",trim($row_Recordset1['mess'])).'<em>';
			echo '</table><p>';
			}
		}
} while ($row_Recordset1 = mysql_fetch_array($Recordset1));

mysql_free_result($Recordset1);
?>
