0 Question: Unable to find data & display in tabular format from two collections through user inputs

question created at Sat, Jun 1, 2019 12:00 AM

Well, I have two collections as BookAPT(Book Appointment) & Client(Client Details), what I am trying to do is get the appointment date from BookAPT collection & Client name from Client collection, with the common field as application Id(AID). I want to display data in tabular format through user input i.e HTML page.

I am working on a project a web application based project, FrontEnd: HTML Backend: PHP Database: MongoDB version v4.0.5 Platform: Windows 10 Server: XAMP

The BookAPT collection is as follows:

{ "_id" : ObjectId("5cf15fa1716b8d1070001373"), "AID" : "APPID40538", "StateSelect" : "Maharashtra", "CitySelect" : "Nashik", "DCSelect" : "SRL", "APTDate" : "08/03/2019" }

{ "_id" : ObjectId("5cf15666716b8d107000136a"), "AID" : "APPID69993", "StateSelect" : "Maharashtra", "CitySelect" : "Pune", "DCSelect" : "SRL - Aundh", "APTDate" : "06/07/2019" }

The Client collection is as follows :

{ "_id" : ObjectId("5cf15f83716b8d1070001372"), "AID" : "APPID40538", "MemberID" : "CORP18097", "Select1" : "Mr.", "firstname" : "Shreyash", "MName" : "Shreyash", "LName" : "Vispute",


{ "_id" : ObjectId("5c9cfe20716b8d3a44007835"), "AID" : "APPID69993", "MemberID" : "CORP89176", "Select1" : "Mr.", "firstname" : "Arun", "MName" : "vijay", "LName" : "sharm",



I usually use the following method to get the data from the single collection the following way through PHP,

php Code:

<!DOCTYPE html>
<!-- Bootstrap core CSS-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/

<!-- Custom fonts for this template-->
<link href="vendors/fontawesome-free/css/all.min.css" rel="stylesheet" 

<!-- Page level plugin CSS-->
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.18/css/

<!-- Custom styles for this template-->
<link href="css/sb-admin.css" rel="stylesheet">

<!--date CSS styles-->
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap- 
datepicker/1.3.0/css/datepicker.css" rel="stylesheet" type="text/css" />

<!-- Java Script Source-->
<script src="js/new.js"></script>


 $m = new MongoDB\Client;

 $collection = $m->retest->BookAPT;



 <!-- Search Appointment Data Table -->
 <div class="card mb-3">
        <div class="card-header">
          <i class="fas fa-table"></i>
          Appointments List</div>
        <div class="card-body">
          <div class="table-responsive">
            <table class="table table-bordered" id="dataTable" 
width="100%" cellspacing="0">
                  <th>Application ID</th>
                  <th>Diagnostic Center</th>
                  <th>city Name</th>
                  <th>Appointment Date</th>

                  <th>Application ID</th>
                  <th>Diagnostic Center</th>
                  <th>city Name</th>
                  <th>Appointment Date</th>


              <?php if (isset($_POST['Submit'])){
              $APID = $_POST['AppID'];
              $DCName = $_POST['dcname'];
              $State = $_POST['state'];
              $City = $_POST['city'];

              $client = $collection->find(array('$or' => array(
              array('AID' => $APID),
              array('DCSelect' => array('$regex'=>$DCName)),


              foreach ($client as $emp){
                <td><?php echo $emp['AID'] ?></td>
                <td><?php echo $emp['DCSelect'] ?></td>
                <td><?php echo $emp['StateSelect'] ?></td>
                <td><?php echo $emp['CitySelect'] ?></td>
                <td><?php echo $emp['APTDate'] ?></td>
                <?php }}?>

        <div class="card-footer small text-muted"></div>

The configuration for monogbd Connection is as follows:

require 'vendor/autoload.php';

$mng = new MongoDB\Driver\Manager();

//echo " Driver connected";

$bw = new MongoDB\Driver\Bulkwrite;


The data should be displayed in tabular format as shown below.

AID firstname APTDate APPID69993 Arun 06-07-2019 APPID40538 Shreyash 08-03-2019

0 Answers 0
source placed here