<?
$query = "SELECT * FROM mess 
WHERE
".$lok."
ORDER BY data 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'])) 
	{ 
	echo '<table width=100%><tr><td class=tb2>';
	echo '<font color=green>'.date($date_format_site2, strtotime($row_Recordset1['data'])).'</font>';
	if($row_Recordset1[$y]==-1) $adresat='ВСЕМ'; else $adresat=$row_Recordset1[$z];
	echo '<br>'.$x.' <b>'.$adresat.'</b>';
	echo '<br>'.str_replace("\n","<br>",trim($row_Recordset1['mess']));
	if($row_Recordset1[$y]==-1)
	echo '<br><a href="mess.php?ms=history&vizavi=-1">Читать все сообщения для ВСЕХ</a>';
	else
	echo '<br><a href="mess.php?ms=history&vizavi='.$row_Recordset1[$y].'">Читать всю переписку с этим автором</a>';
	if($row_Recordset1['pr']==1)
		{
		echo '<br><a href="mess.php?ms=pr&pr='.$row_Recordset1['id_mess'].'"><font color=green>Отправить письмо</font></a>';
		echo '<br><a href="mess.php?ms=edit&pr='.$row_Recordset1['id_mess'].'"><font color=green>Редактировать</font></a>';
		echo '<br><a href="mess.php?ms=del&pr='.$row_Recordset1['id_mess'].'"><font color=green>Удалить</font></a>';
		}
	echo '</table><p>';
	}
} while ($row_Recordset1 = mysql_fetch_array($Recordset1));

mysql_free_result($Recordset1);
?>
