File size: 5.51Kb
<?php
require_once 'db.php';
if (empty($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
$current_user_id = (int)$_SESSION['user_id'];
// Пытаемся получить совпадения.
// Если структура таблицы "matches" у тебя отличается, просто поправим имена полей.
// Здесь предполагается: matches(user1_id, user2_id, created_at)
$sql = "
SELECT
u.id,
u.name,
u.city,
u.about,
u.photo,
CASE
WHEN u.birthdate IS NOT NULL
THEN TIMESTAMPDIFF(YEAR, u.birthdate, CURDATE())
ELSE NULL
END AS age,
m.created_at
FROM matches m
JOIN users u
ON u.id = CASE
WHEN m.user1_id = {$current_user_id} THEN m.user2_id
ELSE m.user1_id
END
WHERE (m.user1_id = {$current_user_id} OR m.user2_id = {$current_user_id})
ORDER BY m.created_at DESC
";
$matches = $mysqli->query($sql);
if (!$matches) {
// если что-то пошло не так с SQL — просто считаем, что нет совпадений,
// чтобы не падал весь сайт
$matches = false;
}
include 'header.php';
?>
<style>
.matches-page-title{
font-size:24px;
font-weight:700;
margin-bottom:10px;
}
.matches-list{
display:flex;
flex-direction:column;
gap:16px;
margin-top:6px;
}
.match-card{
background:#ffffff;
border-radius:22px;
padding:14px 14px 14px;
box-shadow:0 10px 30px rgba(0,0,0,0.05);
display:flex;
gap:14px;
align-items:center;
}
.match-avatar{
flex-shrink:0;
}
.match-avatar img,
.match-avatar-placeholder{
width:82px;
height:82px;
border-radius:999px;
object-fit:cover;
display:block;
}
.match-avatar-placeholder{
background:linear-gradient(135deg,#ffe5f0,#f5ebff);
display:flex;
align-items:center;
justify-content:center;
font-size:34px;
}
.match-main{
flex:1;
min-width:0;
}
.match-name-row{
display:flex;
align-items:baseline;
gap:6px;
margin-bottom:2px;
}
.match-name{
font-size:18px;
font-weight:600;
}
.match-age{
font-size:13px;
color:#ff4f8b;
}
.match-city{
font-size:13px;
color:#7b7287;
margin-bottom:4px;
}
.match-about{
font-size:13px;
color:#4b4454;
max-height:3.2em;
overflow:hidden;
}
.match-actions{
display:flex;
flex-wrap:wrap;
gap:8px;
margin-top:10px;
}
.match-actions a{
text-decoration:none;
}
.btn-secondary-soft{
border-radius:999px;
padding:7px 14px;
border:none;
font-size:13px;
background:#f3f0ff;
color:#5b4f8d;
display:inline-block;
}
@media (max-width:768px){
.match-card{
margin:0 -4px;
border-radius:18px;
}
.match-avatar img,
.match-avatar-placeholder{
width:72px;
height:72px;
}
}
</style>
<div class="matches-page">
<h1 class="matches-page-title">Ваши совпадения</h1>
<?php if (!$matches || $matches->num_rows === 0): ?>
<p style="font-size:14px;color:#7b7287;margin-top:8px;">
У вас пока нет взаимных симпатий. Поставьте ещё несколько лайков в разделе «Анкеты»,
и здесь появятся ваши совпадения 💞
</p>
<?php else: ?>
<div class="matches-list">
<?php while ($row = $matches->fetch_assoc()): ?>
<div class="match-card">
<div class="match-avatar">
<?php if (!empty($row['photo'])): ?>
<img src="/assets/img/<?= htmlspecialchars($row['photo']) ?>" alt="">
<?php else: ?>
<div class="match-avatar-placeholder">😊</div>
<?php endif; ?>
</div>
<div class="match-main">
<div class="match-name-row">
<div class="match-name">
<?= htmlspecialchars($row['name'] ?: 'Без имени') ?>
</div>
<?php if (!is_null($row['age'])): ?>
<div class="match-age"><?= (int)$row['age'] ?> лет</div>
<?php endif; ?>
</div>
<?php if (!empty($row['city'])): ?>
<div class="match-city"><?= htmlspecialchars($row['city']) ?></div>
<?php endif; ?>
<?php if (!empty($row['about'])): ?>
<div class="match-about">
<?= nl2br(htmlspecialchars($row['about'])) ?>
</div>
<?php endif; ?>
<div class="match-actions">
<a href="profile.php?user_id=<?= (int)$row['id'] ?>">
<span class="btn-secondary-soft">Посмотреть профиль</span>
</a>
<a href="messages.php?user_id=<?= (int)$row['id'] ?>">
<button class="btn-primary">Написать</button>
</a>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
<?php endif; ?>
</div>
<?php include 'footer.php'; ?>