Welcome to Praful Bhuskute BlackSpy Praful Bhuskute BlackSpy Praful Bhuskute BlackSpy Praful Bhuskute BlackSpy

Get Data from Database in WordPress to Display content in Template

				
					<?php
/*
Template Name: All Candidate
Template Post Type: post, page, event
 *
 * @package Confit
 * @since Confit 1.0
 */

get_header(); ?>

<style>
    .row {
        margin: auto;
    }

    .modal {
        top: 10%;
        opacity: 1;
    }

    .modal.fade .modal-dialog {
        transform: translate(0, 0%);
    }

    .modal-dialog {
        max-width: 1100px;
        width: 100%;
    }

    .modal-title {
        display: contents;
    }

    .modal-header {
        text-align: center;
        display: inline-block;
    }

    .heading-resume {
        text-align: center;
    }

    .job-title-heading {
        background-image: linear-gradient(-20deg, #3f07a4 0%, #026dea 100%);
        color: #ffffff;
        text-align: center;
        padding: 2px 0px;
        font-weight: 700;
    }

    .user-details .fa {
        width: 20px;
        color: #311eb4;
    }

    .space-bet {
        height: 10px;
    }

    select[multiple],
    select[size] {
        padding: 11px 25px;
    }
</style>
<div class="row">
    <main class="admin-main">
        <section class="admin-content">

            <div class="pull-up">
                <div class="container">
                    <div class="row">

                        <div class="col-md-12">
                            <div class="card">
                                <div class="card-body">
                                    <div class="row">
                                        <div class="col-md-6 my-auto">
                                            <h3 class="m-0">Summary</h3>
                                        </div>
                                    
                                    </div>

                                    <div class="row ">
                                        <div class="col-md-12 p-0">
                                            <div class="table-responsive">
                                                <table class="table table-hover">
                                                    <thead class="">
                                                        <tr>
                                                            <th scope="col">Sr. No.</th>
                                                            <th scope="col">First Name</th>
                                                            <th scope="col">Last Name</th>
                                                            <th scope="col">Mobile No.</th>
                                                            <th scope="col">Tiele</th>
                                                            <th scope="col">Experience</th>
                                                            <th scope="col">Action</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        <?php
                                                        global $wpdb;
                                                        $result = $wpdb->get_results("SELECT * FROM candidate_details");
                                                        foreach ($result as $print) {
                                                        ?>
                                                            <tr>
                                                                <td class="align-middle"><?php echo $print->ID; ?></td>
                                                                <td class="align-middle"><?php echo $print->firstname; ?></td>
                                                                <td class="align-middle"><?php echo $print->lastname; ?></td>
                                                                <td class="align-middle"><?php echo $print->contactnumber; ?></td>
                                                                <td class="align-middle"><?php echo $print->jobtitle; ?></td>
                                                                <td class="align-middle"><?php echo $print->experiance; ?></td>
                                                                <td class="align-middle">
                                                                    <div class="input-group ">
                                                                        <div class="input-group-prepend">
                                                                            <a class="btn btn-white" data-toggle="modal" data-target="#<?php echo $print->ID; ?>">View</a>
                                                                            <button type="button" class="btn btn-white dropdown-toggle dropdown-toggle-split rounded-right" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                                                                <span class="sr-only">Toggle Dropdown</span> </button>
                                                                            <div class="dropdown-menu dropdown-menu-right">
                                                                                <a class="dropdown-item" value="<?php echo $print->ID; ?>">Edit Candidate</a>
                                                                                <a class="dropdown-item" data-toggle="modal" data-target="#<?php echo $print->ID; ?>">Preview</a>
                                                                                <a class="dropdown-item" href="#">Download</a>
                                                                                <div role="separator" class="dropdown-divider"></div>
                                                                                <a class="dropdown-item" href="#">Cancel</a>
                                                                            </div>
                                                                        </div>

                                                                    </div>
                                                                </td>

                                                            </tr>

                                                        <?php
                                                        }
                                                        ?>

                                                    </tbody>
                                                </table>
                                            </div>

                                        </div>
                                        <div class="col-auto ml-auto">
                                            <div>
                                                <nav class="Page navigation example">
                                                    <ul class="pagination">
                                                        <li class="page-item disabled">
                                                            <a class="page-link" href="#" tabindex="-1">Previous</a>
                                                        </li>
                                                        <li class="page-item active"><a class="page-link" href="#">1</a>
                                                        </li>
                                                        <li class="page-item ">
                                                            <a class="page-link" href="#">2 <span class="sr-only">(current)</span></a>
                                                        </li>
                                                        <li class="page-item"><a class="page-link" href="#">3</a></li>
                                                        <li class="page-item">
                                                            <a class="page-link" href="#">Next</a>
                                                        </li>
                                                    </ul>
                                                </nav>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="dropdown">
                                        <h3>Edit Candidate</h3>
                                        <form method="post" action="/candidate-profile/update-candidate-details/">
                                            <select name="update-candidate" size="1">
                                                <option value="" disabled selected>Edit Candidate</option>
                                                <?php
                                                global $wpdb;
                                                $result = $wpdb->get_results("SELECT * FROM candidate_details");
                                                foreach ($result as $print) {
                                                ?>
                                                    <option value="<?php echo $print->ID; ?>">ID: <?php echo $print->ID; ?> Name: <?php echo $print->firstname; ?> </option>
                                                <?php
                                                }
                                                ?>
                                            </select>
                                            <input type="submit" id="save">
                                        </form>

                                    </div>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>





        </section>
    </main>
</div>


<!-- Remove function Start here -->

<div class="dropdown">
    <h3>Delete Candidate</h3>
    <form method="post" action="<?php $_SERVER["PHP_SELF"] ?>">
        <select name="delete-candidate" size="1">
            <option value="" disabled selected>Delete Candidate</option>
            <?php
            global $wpdb;
            $result = $wpdb->get_results("SELECT * FROM candidate_details");
            foreach ($result as $print) {
            ?>
                <option value="<?php echo $print->ID; ?>">ID: <?php echo $print->ID; ?> Name: <?php echo $print->firstname; ?> </option>
            <?php
            }
            ?>
        </select>
        <input type="submit" id="save" value="Delete">
    </form>

</div>
<?php
//var_dump($_POST);
$delete_candidate = $_POST["delete-candidate"];
$id = $delete_candidate;
$table = 'candidate_details';
$delete = $wpdb->delete($table, array('id' => $id));

if ($delete) {
    //echo 'data has been save';
    echo '<script>
    window.location.href = "https://resume.prafulbhuskute.com/candidate-profile/";
    </script>';
}
?>

<!-- Remove function End here -->


<!-- Modal -->

<script>
    function printDiv(divName) {
        var printContents = document.getElementById(divName).innerHTML;
        var originalContents = document.body.innerHTML;

        document.body.innerHTML = printContents;

        window.print();

        document.body.innerHTML = originalContents;

    }
</script>


<?php
foreach ($result as $print) {
?>
    <div class="modal fade" id="<?php echo $print->ID; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog  modal-dialog-align-top-left" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Candidate Profile</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <div class="row" id='printMe'>
                        <div class="col-md-12">
                            <div class="col-md-8 user-details">
                                <p>
                                    <strong> First Name: </strong> <?php echo $print->firstname; ?> <br />
                                    <strong>Last Name: </strong> <?php echo $print->lastname; ?><br />
                                    <strong>Email ID: </strong> <?php echo $print->emailid; ?><br />
                                    <strong>Contact Number: </strong> <?php echo $print->contactnumber; ?><br />
                                    <strong>Display Name: </strong> <?php echo $print->displayname; ?><br />
                                    <strong> Education: </strong><?php echo $print->education; ?><br />

                                    <strong>Job Title: </strong> <?php echo $print->jobtitle; ?><br />

                                    <strong>Experieance: </strong><?php echo $print->experiance; ?> years<br />
                                    <strong>Summery: </strong> <?php echo $print->summery; ?><br />


                                </p>
                                <div class="job-title-heading" style="margin-bottom: 20px;"></div>



                            </div>
                        </div>
                        <hr>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">
                    Close
                </button>

            </div>
        </div>
    </div>
    </div>
<?php
}
?>
<!-- Modal  End -->

<?php get_footer(); ?>
				
			

Drop your queries

Table of Contents

Have A Project In Mind? Let's Get To Work