Link to home
Start Free TrialLog in
Avatar of Mark Miles
Mark MilesFlag for United States of America

asked on

Display SPECIFIC Rows in SQL Database

I have an SQL database with 6 columns.  The data in this column is displayed on the front end of a website.  How do I add a "display" column to the table where I can turn off and on whether that specific row is displayed on the front end of the website? 


User generated image

User generated image

Here is my code..

<div class="mb-3">
                 <!--                 <input type="text" class="form-control" id="omt" name="omt" placeholder="Old Mask">                -->                <select class="maskSelection form-control rt-select" name="omt" multiple="single" required>                      <option value="" disabled selected>Please select mask the patient is returning</option>                   <?php foreach($mask as $m):?>                      <option value="<?php echo $m->bt_item_id; ?>,<?php echo $m->mask_manufacturer;?>,<?php echo $m->mask_approx_cost;?>" ><?php echo $m->mask_name;?></option>                   <?php endforeach;?>                                  </select>               </div>               <div class="mb-3">                 <!-- <input type="text" class="form-control" id="nmt" name="nmt" placeholder="New mask"> -->                                <select class="maskSelection form-control rt-select" name="nmt" multiple="single" required>                   <option value="" disabled selected>Please select mask you are issuing the patient</option>                   <?php foreach($mask as $m):?>                      <option value="<?php echo $m->bt_item_id; ?>"><?php echo $m->mask_name;?></option>                   <?php endforeach;?>                                  </select>

Open in new window

Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Hey Mark,

The data displayed in your front end will have been retrieved from the database using a SQL query. You will need to add a WHERE clause to that query to limit what data is returned. How you use that WHERE clause will of course depend on whether you have something you can filter on in your table.

If you don't then you'll need to add a new column. Your screenshot above looks like PHPMyAdmin, so you'd want to select your table, and then click on the Structure tab. This will allow you to add a new column (such as a Boolean type column, called 'display'). You'll probably want to set the default value to true.

Once you've done that, update your PHP SQL query to include :

WHERE display = true;
Avatar of Mark Miles

ASKER

@chris one of the issues of I don't know where to enter the WHERE condition?
You've only shown a small snippet of code, which is clearly part of a larger project. In the code above, the records used to populate the <select> options come from a variable called $mask, so you'd need to find where you populate that. Could be further up the same file as the code above or it could be in a totally different file. Without knowing your setup, or how your application is coded, it's impossible to give you a specific answer.

If you're using a decent IDE (such as Visual Studio Code), then you can do a quick search across your entire project - search for '$mask' and check the code. You may have to manually work your way up the stack once you've found it until you can find the actual SQL that#s been used.
@chris I did not write this code.. that is why I am here for assistance.. here is the entire code from that page.. does it show where it is pulling from?
<ul class="nav nav-tabs" id="myTab" role="tablist">
  <li class="nav-item" role="presentation">
    <button class="nav-link active" id="home-tab" data-bs-toggle="tab" data-bs-target="#home" type="button" role="tab" aria-controls="home" aria-selected="true">New Exchange</button>
  </li>
  <li class="nav-item" role="presentation">
    <button class="nav-link" id="profile-tab" data-bs-toggle="tab" data-bs-target="#profile" type="button" role="tab" aria-controls="profile" aria-selected="false">My Orders</button>
  </li>
  
</ul>
<div class="tab-content" id="myTabContent">
  <div class="tab-pane fade show active exchange-margin" id="home" role="tabpanel" aria-labelledby="home-tab">
     

     <?php
      if(isset($_GET['order_complete'])){
          if ($_GET['order_complete'] == '1') {
             ?>
             <div class="alert alert-success alert-dismissible fade show col-md-6 mb-5" style="margin:0 auto;" role="alert">
              <strong>Success!</strong> Order has been sent.
              <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            </div>
             <?php
       
          }
      }
      ?>

     <div class="row text-center button-row">
      <div class="col">
         <button class="exchange-button" onclick="openForm();">+ New Mask Exchange</button>
      </div>
   </div>

   <div id="form-row" class="row hidden mt-2">
      <div class="col-md-6 mx-auto">
         <card>
            <h2 class="text-center mb-3">New Exchange Form</h2>
            <form action="" method="POST">

              <div class="row mb-3">
                 <div class="col">
                    <input type="text" class="form-control" name="first_name" placeholder="First" required>
                 </div>
                 <div class="col">
                    <input type="text" class="form-control" name="last_initial" maxlength="1" placeholder="Last Initial" required>
                 </div>
              </div>
                
              
              <div class="row mb-3">
                 <div class="col">
                    <input type="text" class="form-control" name="business_unit" value="<?php echo $_SESSION['bu']; ?>" required>
                 </div>
                 <div class="col">
                    <input type="text" class="form-control" name="brightree_id" placeholder="Brightree ID" required>
                 </div>
              </div>
              

             
              <div class="mb-3">
                 <!--
                <input type="text" class="form-control" id="omt" name="omt" placeholder="Old Mask">
               -->
               <select class="maskSelection form-control rt-select" name="omt" multiple="single" required>
                     <option value="" disabled selected>Please select mask the patient is returning</option>
                  <?php foreach($mask as $m):?>
                     <option value="<?php echo $m->bt_item_id; ?>,<?php echo $m->mask_manufacturer;?>,<?php echo $m->mask_approx_cost;?>" ><?php echo $m->mask_name;?></option>
                  <?php endforeach;?>
                  
               </select>
              </div>

              <div class="mb-3">
                <!-- <input type="text" class="form-control" id="nmt" name="nmt" placeholder="New mask"> -->

               


               <select class="maskSelection form-control rt-select" name="nmt" multiple="single" required>
                  <option value="" disabled selected>Please select mask you are issuing the patient</option>
                  <?php foreach($mask as $m):?>
                     <option value="<?php echo $m->bt_item_id; ?>"><?php echo $m->mask_name;?></option>
                  <?php endforeach;?>
                  
               </select>

              </div>

              


              <p class="mt-2" style="font-style: italic;"><span style="color:red;font-weight: bold;">Notice:</span> Please use diligence when selecting the masks and sizes. This will update official records in our system to insure the patient gets the appropriate mask and size for their next resupply. The sizing and mask type must be accurate.</p>
              <button type="submit" name="submit" class="btn btn-primary">Submit</button>
            </form>
            
         </card>
      </div>
   </div>


  </div>
  <div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">
     
     <div id="form-row" class="row mt-5">
      <div class="col mx-auto">
         <div class="table-responsive">
            <table class="table table-hover table-striped processed" style="width:100%;">
               <thead class="thead-dark">
                  <tr>
                     <td>First Name</td>
                     <td class="text-center">Last</td>
                     <td>Old Mask</td>
                     <td>New Mask</td>      
                     <td>Brightree ID</td>
                     <td>Sales Order</td>
                     <td class="text-center">Status</td>
                  </tr>
               </thead>
               <tbody>
                  <?php $order = $Function->RTOrderHistory(); ?>
                  <?php foreach($order as $o):?>

                     <tr>
                        <td><?php echo $o->first_name;?></td>
                        <td class="text-center" style="width:5%;"><?php echo $o->last_initial;?></td>
                        <td><?php echo $Function->getMaskFromID($o->old_mask_type)[0]->mask_name; ?></td>
                        <td><?php echo $Function->getMaskFromID($o->new_mask_type)[0]->mask_name; ?></td>
                        <td><?php echo $o->bright_ID;?></td>
                        <td><?php echo $o->sales_order;?></td>

                        <?php
                        if($o->status == '1') {
                           echo '<td class="text-center" style="background:blue;color:white;">Pending CSR</td>';
                        } else if($o->status == '2') {
                           echo '<td class="text-center" style="background:orange;color:white;">Pending Email</td>';
                        } else if($o->status == '3') {
                           echo '<td class="text-center" style="background:green;color:white;">Complete</td>';
                        } else {
                           echo '<td class="text-center" style="background:red;color:white;">Pending Admin</td>';
                        }
                        ?>

                     </tr>

                     
                  <?php endforeach;?>
               </tbody>
            </table>
         </div>
      </div>

   </div>
  </div>
  

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
As Chris points out, $m seems to be the structure that gets the dataset.

The query shoukd be closer to the top.

You are posting the rendering of info into the page to be furnished.

See if you can search for a select.

It could very well be part of an include file ....