File "update_marquee.php"

Full path: /home/julaysp1/public_html/admin/update_marquee.php
File size: 4.88 B (4.88 KB bytes)
MIME-type: text/x-php
Charset: utf-8

Download   Open   Edit   Advanced Editor &nnbsp; Back

<?php
include_once("header.php");

// Prepare the SQL query to fetch existing records
$sql = "SELECT * FROM marquee";
$result = $conn->query($sql);

// Initialize an array to store the users
$users = array();

// Check if any records were found
if ($result->num_rows > 0) {
    // Fetch all rows as an associative array and store them in the $users array
    while ($row = $result->fetch_assoc()) {
        $users[] = $row;
    }
} else {
    $users = []; // No users found
}

// Check if the form has been submitted for updating numbers
if (isset($_POST['update'])) {
    $updateSuccess = true; // Flag to track success

    foreach ($_POST['numbers'] as $id => $new_number) {
        $new_number_encoded = base64_encode($new_number); // Encode here
        $query = "UPDATE marquee SET marquee_text = ? WHERE id = ?";
        $stmt = $conn->prepare($query);

        if ($stmt) { // Check if statement was prepared successfully
            $stmt->bind_param("si", $new_number_encoded, $id);
            if (!$stmt->execute()) {
                $updateSuccess = false; // Update failed
            }
            $stmt->close();
        } else {
            $updateSuccess = false; // Prepare failed
        }
    }

    // Show alert based on the success of the update operation
    if ($updateSuccess) {
        echo '<div class="alert alert-info" style="position: fixed; top: 20px; right: 20px; z-index: 1033;">
                <p>
                    <span class="fa fa-fw fa-info-circle me-1"></span>
                    <span class="title"></span>
                    <span class="message">Successfully Updated All</span>
                </p>
                <a class="close" aria-label="Close" onclick="this.parentElement.style.display=\'none\';">
                    <i class="fa fa-times"></i>
                </a>
              </div>';
    } else {
        echo '<div class="alert alert-danger" style="position: fixed; top: 20px; right: 20px; z-index: 1033;">
                <p>
                    <span class="fa fa-fw fa-exclamation-circle me-1"></span>
                    <span class="message">Failed to Update Some Entries</span>
                </p>
                <a class="close" aria-label="Close" onclick="this.parentElement.style.display=\'none\';">
                    <i class="fa fa-times"></i>
                </a>
              </div>';
    }
}

// Fetch all numbers from the marquee_text table
$query = "SELECT id, page_name, marquee_text FROM marquee";
$result = mysqli_query($conn, $query);
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="path/to/your/css/styles.css"> <!-- Ensure to include your styles -->
    <title>Update Marquee Text</title>
</head>
<body>
    <main id="main-container">
        <div class="content">
            <div class="card mb-3 p-3">
                <h4 class="py-1">নোটিশ টেক্স আপডেট করুন এখান থেকে</h4>
                <form method="POST" action="">
                    <table border="1" class="table">
                        <tr>
                            <th>ID</th>
                            <th>Page Name</th>
                            <th>Number</th>
                        </tr>
                        
                        <?php
                        // Loop through the result and display numbers
                        if (mysqli_num_rows($result) > 0) {
                            while ($row = mysqli_fetch_assoc($result)) {
                                echo "<tr>";
                                echo "<td><b>" . $row['id'] . ":</b></td>";
                                echo "<td>" . $row['page_name'] . "</td>";
                                // Each number has a textarea for editing
                                echo "<td>
                                    <textarea class='form-control mb-2' name='numbers[" . $row['id'] . "]' required>" . base64_decode($row['marquee_text']) . "</textarea>
                                </td>";
                                echo "</tr>";
                            }
                        } else {
                            echo "<tr><td colspan='3'>No numbers found</td></tr>";
                        }
                        ?>
                    </table>
                    <input type="submit" class="btn btn-secondary mx-3" name="update" value="Update All">
                </form>
            </div>
        </div>
    </main>

    <?php include_once("footer.php"); ?>
    
    <script>
        $(document).ready(function () {
            // Set active class on the appropriate navigation link
            $('a.nav-main-link').removeClass("active");
            $('a.update_marquee').addClass("active");
        });
    </script>
</body>
</html>

<?php 
// Close the database connection here, at the end of your script
mysqli_close($conn); 
?>