<!DOCTYPE html>
<html dir="rtl">
<head>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
    <style>
        .vertical-table {
            display: flex;
            flex-direction: column;
        }
        .vertical-table th,
        .vertical-table td {
            text-align: center;
        }
        .vertical-table, th, td {
            border: 1px solid black;
            border-collapse: collapse;
            padding: 5px;
            text-align: right; /* Text alignment is set to right */
        }
        .center-form {
            display: flex;
            justify-content: center;
            margin-top: 20px;
        }
        
        .table-container {
            margin: 0 auto; /* Center the table */
            float: right; /* Float the table to the right */
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="center-form">
            <form method="GET" class="form-inline">
                <input class="form-control mr-sm-2" type="text" name="search" placeholder="اكتب الكود او الاسم"   />
                <button class="btn btn-primary" type="submit" name="btn-search">بحث بالكود</button>
            </form>
        </div>


        <?php
            // search.php

            $username = "u890837200_LRoR4";
            $password = "iiwlaXa1bG";
            $database = new PDO("mysql:host=localhost; dbname=u890837200_EbuAp;", $username, $password);

            if (isset($_GET['search'])) {
                $SEARCH = $database->prepare("SELECT * FROM tableName WHERE Code LIKE :value OR Name LIKE :value ");
                $SEARCH_VALUE = "%" . $_GET['search'] . "%";

                $SEARCH->bindParam("value", $SEARCH_VALUE);
                $SEARCH->execute();

                echo '<table class="table table-bordered container">';
                echo '<thead>';
                echo '<tr>';
                echo '<th>الكود</th>';
                echo '<th>الاسم</th>';
                echo '<th>الحصة الاولي</th>';
                echo '<th>الامتحان</th>';
                echo '<th>الحصة الثانية</th>';
                echo '<th>الامتحان</th>';
                echo '<th>الحصة الثالثة</th>';
                echo '<th>الامتحان</th>';
                echo '<th>الحصة الرابعة</th>';
                echo '<th>الامتحان</th>';
                echo '<th>الحصة الخامسة</th>';
                echo '<th>الامتحان</th>';
                echo '<th>الحصة السادسة</th>';
                echo '<th>الامتحان</th>';
                echo '<th>الحصة السابعة</th>';
                echo '<th>الامتحان</th>';
                echo '<th>الحصة الثامنة</th>';
                echo '<th>الامتحان</th>';
                echo '</tr>';
                echo '</thead>';
                echo '<tbody>';

                foreach ($SEARCH as $data) {
                    echo '<tr>';
                    echo '<td>' . $data['Code'] . '</td>';
                    echo '<td>' . $data['Name'] . '</td>';
                    echo '<td>' . $data['M1'] . '</td>';
                    echo '<td>' . $data['H1'] . '</td>';
                    echo '<td>' . $data['M2'] . '</td>';
                    echo '<td>' . $data['H2'] . '</td>';
                    echo '<td>' . $data['M3'] . '</td>';
                    echo '<td>' . $data['H3'] . '</td>';
                    echo '<td>' . $data['M1'] . '</td>';
                    echo '<td>' . $data['H1'] . '</td>';
                    echo '<td>' . $data['M2'] . '</td>';
                    echo '<td>' . $data['H2'] . '</td>';
                    echo '<td>' . $data['M3'] . '</td>';
                    echo '<td>' . $data['H3'] . '</td>';
                    echo '<td>' . $data['M2'] . '</td>';
                    echo '<td>' . $data['H2'] . '</td>';
                    echo '<td>' . $data['M3'] . '</td>';
                    echo '<td>' . $data['H3'] . '</td>';
                    echo '</tr>';
                }

                echo '</tbody>';
                echo '</table>';
            }
        ?>

    </div>
</body>
</html>