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>
<html>
<head>
<title>Test</title>
<!-- Bootstrap core CSS-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/
 bootstrap/4.0.0/css/bootstrap.min.css" 
 integrity="sha384- 
 Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" 
 crossorigin="anonymous">

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

<!-- Page level plugin CSS-->
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.18/css/
  dataTables.bootstrap4.min.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>

<?php

 include_once("config2.php");
 $m = new MongoDB\Client;

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

?>

</head>
<body>

 <!-- 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">
              <thead>
                <tr>
                  <th>Application ID</th>
                  <th>Diagnostic Center</th>
                  <th>State</th>
                  <th>city Name</th>
                  <th>Appointment Date</th>
                </tr>
              </thead>

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

              </tfoot>
              <tbody>

              <?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){
                ?>
                <tr>
                <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>
                </tr>
                <?php }}?>
              </tbody>

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

The configuration for monogbd Connection is as follows:

<?php
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
0 Answers 0
source placed here