如何从数据库中以模态输出特定信息

时间:2018-08-23 13:53:21

标签: javascript php html database modal-dialog

我正在尝试在表中显示有关该用户的更多信息。目的是要在模式中查看有关用户的更多信息,而不是在表概述中看到的信息。不幸的是,我没有设法仅在模式中显示各个用户的信息。我已经有以下代码无法正常运行。此刻,模态仍然空着。

问候

admin.php

<?php
include('connection.php');

if( !empty($_POST) ){

    foreach( $_POST as $key_post => $value_post ){

        if (preg_match('/delete_/i',$key_post) ) {

            $id_to_delete = (integer) str_replace('delete_','', $key_post);

            $deleteQuery = "DELETE FROM card WHERE id = " . $id_to_delete;
            $statement = $pdo->prepare($deleteQuery);
            $statement->execute();
        }
    }
}
include('read.php');

if( !empty($_POST) ){

    foreach( $_POST as $key_post => $value_post ){

        if (preg_match('/viewDetail_/i',$key_post) ) {

            $id_to_view = (integer) str_replace('viewDetail_','', $key_post);

            $viewQuery = "SELECT * FROM card WHERE id = " . $id_to_view;
            $statement = $pdo->prepare($viewQuery);
            $statement->execute();
            $viewResult = $statement->fetchAll();
        }
    }
}
?>

  <form action="admin.php" method="post">
                <div class="table-wrapper">
                    <div class="table-scroll">
                        <table id="myTable">
                            <tr>
                                <th>ID</th>
                                <th>Kartentyp</th>
                                <th>Absender</th>
                                <th>Empfänger</th>
                                <th>Sendedatum</th>
                                <th id="smallCol">Verschickt</th>
                                <th id="smallCol">Bestätigung</th>
                                <th>Edit</th>
                            </tr>

                            <?php
                            foreach ($result as $row) {
                                if ($row['Dispatched'] == 0) {
                                    $dispatched = 'Pending';
                                } else {
                                    $dispatched = 'Versendet';
                                }
                                ?>
                                <tr class="Alle <?php echo $row['Category']; ?> <?php echo $row['Dispatched']; ?>">
                                    <td><?php echo $row['ID']; ?></td>
                                    <td><?php echo $row['Category']; ?></td>
                                    <td><?php echo $row['Sender']; ?></td>
                                    <td><?php echo $row['Receiver']; ?></td>
                                    <td><?php echo $row['SendDate']; ?></td>
                                    <td><?php echo $dispatched; ?></td>
                                    <td>Placeholder</td>
                                    <td>
                                        <input type="submit" name="delete_<?php echo $row['ID']; ?>" value="delete" >
                                        <input type="submit" name="viewDetail_<?php echo $row['ID']; ?>" value="modal" data-target="modal1" class="modal-trigger">
                                    </td>
                                </tr>
                                <?php
                            }
                            ?>
                        </table>
                    </div>
                </div>
            </form>
        <br>
        <div class="row">
            <button class="btn waves-effect waves-light" type="submit" name="action">Absenden
                <i class="material-icons right">send</i>
            </button>
        </div>
        <div id="modal1" class="modal">
            <div class="modal-content">
                <h4>Modal Header</h4>
                <div class="table-wrapper">
                    <div class="table-scroll">
                        <table id="myTable">
                            <tr>
                                <th>ID</th>
                                <th>Kartentyp</th>
                                <th>Absender</th>
                                <th>Empfänger</th>
                                <th>Sendedatum</th>
                                <th id="smallCol">Verschickt</th>
                                <th id="smallCol">Bestätigung</th>
                            </tr>

                            <?php
                            foreach ($viewResult as $row){ ?>
                                <tr>
                                    <td><?php echo $row['ID']; ?></td>
                                    <td><?php echo $row['Category']; ?></td>
                                    <td><?php echo $row['Sender']; ?></td>
                                    <td><?php echo $row['Receiver']; ?></td>
                                    <td><?php echo $row['SendDate']; ?></td>
                                    <td><?php echo $dispatched; ?></td>
                                    <td>Placeholder</td>
                                 </tr>
                            <?php
                            }
                            ?>
                        </table>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <a href="" class="modal-close waves-effect waves-green btn-flat">Zurück</a>
            </div>
        </div>

read.php

<?php
include('connection.php');

$statement = $pdo->prepare("SELECT * FROM card ORDER BY ID ASC");
$statement->execute();
$result = $statement->fetchAll();
if ($statement->rowCount() > 0) {
    foreach ($statement->fetchAll() as $row) {
        $id = $row['ID'];
        $imagePath = $row["ImagePath"];
        $sender = $row["Sender"];
        $senderEmail = $row["SenderEmail"];
        $receiver = $row["Receiver"];
        $receiverEmail = $row["ReceiverEmail"];
        $subject = $row["Subject"];
        $text = $row["Text"];
        $sendDate = $row["SendDate"];
        $dispatched = $row["Dispatched"];
        $category = $row['Category'];

    }
}
?>

0 个答案:

没有答案