Louie
Louie

Reputation: 319

How to get the data from another php file by selecting an option in a dropdown list?

I have a dropdown list with options pending and approved. Both have separate PHP file for the sorting, and so I want to ask if there's a way that when I select pending, the query i've done from my pendinglist.php will be shown in the page? same with the approvedlist.php . If there's a way to do it, can someone tell me how and what? Should I use js? Please help..

approvedlist.php

<?php
include 'dbcontroller.php';
$sql = "SELECT * FROM requests where status='approved' ORDER by date DESC";
$result = $conn->query($sql);

?>
<table>
    <thead>
        <tr>
            <th>Name</th>
            <th>Batch Year</th>
            <th>Section</th>
            <th>Action</th>
        </tr>
    </thead>
       <tbody>
        <?php
            if ($result->num_rows > 0) {
                // output data of each row
                while($row = $result->fetch_assoc()) {
                    echo '<tr>';
                    echo '<td>'.$row['firstname'].' '.$row['lastname'].' </td>';
                    echo '<td>'.$row['batchYr'].'</td>';
                    echo '<td>'.$row['section'].'</td>'; 

                 }                   
            }
            else {
                echo "No records found.";
            }
            $conn->close();         
        ?>  
    </tbody>
</table>

I have the same code in my pendinglist.php except their query:

$sql = "SELECT * FROM requests where status='pending' ORDER by date DESC";

Upvotes: 2

Views: 117

Answers (2)

Sriram S
Sriram S

Reputation: 543

Get the selected option in a variable and pass it using webservice.it is so simple if u send i will post the js code

Upvotes: 2

Akshay Shenoy
Akshay Shenoy

Reputation: 119

You can include both php files in your page. Ensure that they are within unique selectors by wrapping them with a class or ID. All your javascript needs to do then is, based on the value in the dropdown, hide the DOM which is not needed

Upvotes: 1

Related Questions