File Manager
Editing: all_accounts.php
<?php require_once 'security.php'; require_once 'functions.php'; // Database connection $servername = "127.0.0.1:3306"; $username = "u404542307_dacotywebsites"; $password = "daCotywebs1te5"; $database = "u404542307_eizon"; $conn = new mysqli($servername, $username, $password, $database); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Get search query from the URL $search = isset($_GET['search']) ? trim($_GET['search']) : ''; // Base query for fetching accounts $base_query = " SELECT u.id, p.username AS profile_username, u.username AS user_username, p.profile_image, p.description FROM users u LEFT JOIN cards c ON u.id = c.user_id LEFT JOIN profiles p ON u.id = p.user_id "; // Add search condition if a search term is provided if (!empty($search)) { $search = $conn->real_escape_string($search); // Sanitize the search term $base_query .= " WHERE p.username LIKE '%$search%' OR u.username LIKE '%$search%' OR p.description LIKE '%$search%' "; } // Group and order by card count (for relevance) $base_query .= " GROUP BY u.id, p.username, u.username, p.profile_image, p.description ORDER BY COUNT(c.user_id) DESC "; // Pagination logic $accounts_per_page = 20; $page = isset($_GET['page']) ? (int)$_GET['page'] : 1; $offset = ($page - 1) * $accounts_per_page; // Query to get the total number of accounts (for pagination) $total_accounts_query = " SELECT COUNT(DISTINCT u.id) as total FROM users u LEFT JOIN cards c ON u.id = c.user_id LEFT JOIN profiles p ON u.id = p.user_id "; if (!empty($search)) { $total_accounts_query .= " WHERE p.username LIKE '%$search%' OR u.username LIKE '%$search%' OR p.description LIKE '%$search%' "; } $total_result = $conn->query($total_accounts_query); if (!$total_result) { die("Error fetching total accounts: " . $conn->error); } $total_accounts = $total_result->fetch_assoc()['total']; $total_pages = ceil($total_accounts / $accounts_per_page); // Query to get paginated results $paginated_query = $base_query . " LIMIT $accounts_per_page OFFSET $offset"; $accounts = $conn->query($paginated_query); if (!$accounts) { die("Error fetching paginated accounts: " . $conn->error); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>All Accounts</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css"> <link rel="stylesheet" href="e-commerce.css"> <link rel="icon" href="/favicon.ico" type="image/x-icon"> <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"> <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png"> <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"> <link rel="manifest" href="/site.webmanifest"> <link rel="manifest" href="/manifest.json"> <style> /* All Accounts Page Styles */ /* Account Cards Layout */ .accounts-container { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 20px; padding: 20px; } .accounts-container a{ text-decoration: none; } /* Individual Account Card */ .account-card { background: #fff; border: 1px solid #ddd; border-radius: 10px; padding: 10px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3); text-align: center; transition: transform 0.3s ease; } .account-card:hover { transform: scale(1.05); /* Zoom effect on hover */ } .account-card img { width: 100px; height: 100px; border-radius: 50%; object-fit: cover; } .account-card h4 { font-size: 16px; margin: 10px 0; color: #007BFF; } .account-card p { font-size: 14px; color: #555; } .account-card a { text-decoration: none; color: #007BFF; font-weight: bold; } /* Pagination Styles */ .pagination { text-align: center; margin: 20px 0; } .pagination a { text-decoration: none; padding: 10px; background: #007BFF; color: white; border-radius: 5px; margin: 0 5px; } .pagination a:hover { background: #0056b3; } .pagination span { margin: 0 10px; font-size: 16px; } /* Search Form Styling */ .search-form { margin: 60px 5px 20px 7px; display: flex; justify-content: center; } .search-form input { padding: 8px; font-size: 16px; width: 250px; margin-right: 10px; border-radius: 5px; border: 1px solid #ddd; } .search-form button { padding: 8px 15px; font-size: 16px; background: orange; color: white; border: none; border-radius: 5px; } .search-form button:hover { background: #0056b3; } .account-description { display: -webkit-box; -webkit-line-clamp: 3; /* Limits to 2 lines */ -webkit-box-orient: vertical; overflow: hidden; text-overflow: ellipsis; white-space: normal; } .username { display: -webkit-box; -webkit-line-clamp: 1; /* Limits to 2 lines */ -webkit-box-orient: vertical; overflow: hidden; text-overflow: ellipsis; white-space: normal; } </style> </head> <body> <?php include 'header.php'; ?> <!-- Search Form --> <form method="GET" action="all_accounts.php" class="search-form"> <input type="text" name="search" placeholder="Search accounts by name or description" value="<?= htmlspecialchars($search); ?>"> <button type="submit">Search</button> </form> <div class="accounts-container"> <?php while ($account = $accounts->fetch_assoc()) { ?> <a href="/profile.php?user=<?= htmlspecialchars($account['profile_username'] ?: $account['user_username']); ?>"> <div class="account-card"> <img src="<?= htmlspecialchars($account['profile_image'] ?: 'images/profile_avatar.jpg'); ?>" alt="Profile Image of <?= htmlspecialchars($account['profile_username'] ?: $account['user_username']); ?>"> <h4 class="username"> <?= htmlspecialchars($account['profile_username'] ?: $account['user_username']); ?> </h4> <p class="account-description"><?= htmlspecialchars($account['description'] ?: 'No description added'); ?></p> </div> </a> <?php } ?> </div> <!-- Pagination --> <div class="pagination"> <?php if ($page > 1) { ?> <a href="all_accounts.php?page=<?= $page - 1; ?>&search=<?= urlencode($search); ?>">Previous</a> <?php } ?> <span>Page <?= $page; ?> of <?= $total_pages; ?></span> <?php if ($page < $total_pages) { ?> <a href="all_accounts.php?page=<?= $page + 1; ?>&search=<?= urlencode($search); ?>">Next</a> <?php } ?> </div> <?php include 'footer.php'; ?> <script> function openNav() { document.getElementById("myNav").style.width = "250px"; } function closeNav() { document.getElementById("myNav").style.width = "0"; } </script> <script src="e-commerce.js"></script> </body> </html>
💾 Save
⬅ Back