Result does not fetch according to the condition set

I’m creating dynamic tabs with dynamic content by using Bootstrap in PHP Mysql. what I want to do here is, display the order_date on the nav-tab and the content of each nav-tab will be displayed by the date of the customer made their orders. The date in each nav-tab can be shown properly according to the condition set, but the content of each nav-tab does not show according to the condition set. It just displays all of the data. Can I know how can I display the content according to the condition set? Let’s say I clicked on the ‘2021-09-09’ tab, the order that is only made on this date will be shown as the content of this nav_tab. Any form of help will be appreciated. thanks in advance!

<?php 
        $tab_query = "SELECT id,cast(order_datetime as date) AS ordered_date , order_status FROM ordered_items GROUP BY ordered_date order by order_datetime DESC LIMIT 7";
        $tab_result = mysqli_query($conn, $tab_query);
        $tab_menu = '';
        $tab_content = '';
        $i = 0;
        while($row = mysqli_fetch_array($tab_result))
        {
         if($i == 0)
         {
          $tab_menu .= '
           <li class="active"><a href="#'.$row["ordered_date"].'" data-toggle="tab">'.$row["ordered_date"].'</a></li>
          ';
          $tab_content .= '
           <div id="'.$row["ordered_date"].'" class="tab-pane fade in active">
          ';
         }
         else
         {
          $tab_menu .= '
           <li><a href="#'.$row["ordered_date"].'" data-toggle="tab">'.$row["ordered_date"].'</a></li>
          ';
          $tab_content .= '
           <div id="'.$row["ordered_date"].'" class="tab-pane fade">
          ';
         }
         $product_query = "SELECT*, cast(order_datetime as date) AS products_ordered_date , order_status FROM ordered_items 
         LEFT JOIN products ON ordered_items.product_id = products.id
         WHERE order_datetime = '".$row["ordered_date"]."'";
         $product_result = mysqli_query($conn, $product_query);
         if(!mysqli_num_rows($product_result)) {    
          $tab_content .=  '<tr>
          <td colspan="5">
              <div class="badge badge-danger">No Order Found</div>
          </td>
        </tr>';         
          }
         while($sub_row = mysqli_fetch_array($product_result))
         {
          $tab_content .= '
          
          <tr>
          <td>
          #'.$sub_row["order_id"].'
          </td>
          <td>
          '.$sub_row["product_title"].'
          </td>
          <td>
          '.$sub_row["quantity"].'
          </td>
          <td>
          '.$sub_row["products_ordered_date"].'
          </td>
          <td>
          '.$sub_row["delivery_date"].'
          </td>
          </tr>
        
   ';
         }
         $tab_content .= '<div style="clear:both"></div></div>';
         $i++;
        }
?>

 <div class="col-12">
  <div class="card">
    <div class="card-header">
      <h4 class="card-title"> All Products</h4>
      <span>
        <a href="download-list/download-products.php" class="btn btn-info float-right mb-3"><i class="fa fa-download" aria-hidden="true"></i> Download Products List</a>
      </span>
      <span>
        <a href="download-list/download-products.php" class="btn btn-info float-right mb-3"><i class="fa fa-download" aria-hidden="true"></i> Download Products List</a>
      </span>
    </div>
      <div class="card-body">
      <ul class="nav nav-tabs">
      <li class="nav-item">
    <ul class="nav nav-tabs">
    <?php echo $tab_menu; ?>
    </ul>
      </li>
      </ul>
      </div>

      <div class="card-body">
                <div class="table-responsive" style="max-height: 70vh">
                  <table class="table">
                    <thead class="text-primary">
                      <th style=" position: sticky;top: 0; background: white" ;>
                        Order no
                      </th>
                      <th style=" position: sticky;top: 0; background: white" ;>
                        Product Name
                      </th>
                      <th style=" position: sticky;top: 0; background: white" ;>
                        Quantity
                      </th>
                      <th style=" position: sticky;top: 0; background: white" ;>
                        Order Date
                      </th>
                      <th style=" position: sticky;top: 0; background: white" ;>
                        Recieve by
                      </th>
                          <tr>
                          <?php echo $tab_content; ?>
                          </tr>
                     
                    </tbody>
                  </table>
                </div>
              </div>

I’m trying to be nice as possible, but I’m going to give my perspective and opinion on Bootstrap. Bootstrap should be learned second as people should have a solid foundation of HTML/CSS before something that is supposed to aid id DESIGNING websites NOT DEVELOPING them.

With that said I would look into how to use Flex and Grids in CSS to design the HTML. Table are OK, but with Flex and Grids it is show much easier. I am sure Bootstrap has that as well though I don’t use it.

I don’t see any form (order) in that spaghetti code and from you description you have your logic all wrong. You want to take things separately as it will simplify things. First, you want to display any data that you actually do have and want to display. Here’s a example from one of my websites.

    <article class="cms">
        <img class="article_image"
             src="<?php echo htmlspecialchars($record['image_path']); ?>" <?= getimagesize($record['image_path'])[3] ?>
             alt="article image">
        <h2><?= $record['heading'] ?></h2>
        <span class="author_style">Created by <?= $record['author'] ?>
                on <?= style_date($record['date_added']) ?>
        </span>

        <?php
        /*
         * Display code using highlight.js that shows
         * the code in proper format and highlighting by
         * call the codingTags() function.
         */
        $content = codingTags($record['content']);
        ?>

        <p><?= nl2br($content) ?></p>
        <?php echo (isset($_SESSION['id'])) ? '<a class="editButton" href="edit.php?id= ' . urldecode($record['id']) . '">Record ' . urldecode($record['id']) . '</a>' : null; ?>
    </article> 

The most import line is the second line from the bottom as that will ONLY display if an administrator or a person with access in order to go to the edit page.

Here’s a part of the edit page:

<form id="formData" class="form_classes" action="edit.php" method="post" enctype="multipart/form-data">
    <input type="hidden" name="cms[id]" value="<?= $id ?>">
    <input type="hidden" name="cms[user_id]" value="<?= $_SESSION['id'] ?>">
    <input type="hidden" name="cms[author]" value="John Pepp">
    <input type="hidden" name="cms[date_updated]" value="<?= $date_updated ?>">
    <input type="hidden" name="action" value="upload">
    <input type="hidden" name="cms[image_path]" value="<?= $record['image_path'] ?>">
    <img src="<?= $_SESSION['old_image'] ?>" alt="current image">
    <br>
    <div class="file-style">
        <input id="file" class="file-input-style" type="file" name="image" value="<?= $record['image_path'] ?>">
        <label for="file">Select file</label>
    </div>
    <div class="heading-style">
        <label class="heading_label_style" for="heading">Heading</label>
        <input class="enter_input_style" id="heading" type="text" name="cms[heading]" value="<?= $record['heading'] ?>"
               tabindex="1" required autofocus>
    </div>
    <div class="content-style">
        <label class="text_label_style" for="content">Content</label>
        <textarea class="text_input_style" id="content" name="cms[content]"
                  tabindex="2"><?= $record['content'] ?></textarea>
    </div>
    <div class="submit-button">
        <button class="form-button" formaction="delete.php?id=<?= $id ?>"
                onclick="return confirm('Are you sure you want to delete this item?');">Delete
        </button>
        <button class="form-button" type="submit" name="submit" value="enter">submit</button>
    </div>
</form>

Notice no mysqli or PDO (my recommendation) in either of those examples or very little. The bottom line no matter how you about doing it even if it is using Bootstrap, take things in logical chunks.

  1. Design the HTML/CSS first as this will give you want it to look like.
  2. Display all the information that needs to be displayed in order for it to look nice and work.
  3. Show or Hide links depending on what you are doing to take to the pages where the data can be edited or displayed separately (?).
  4. Have in the back of your mind on how you have the database table structured and how you are going to handle CRUD (Create, Read, Update and Delete) the data.

Even if you are using Bootstrap have solid knowledge of HTML/CSS as that will help you tremendously. Take time to follow an online tutorial even if you don’t do the whole tutorial as it will help.

Hopes This Helps my ramblings and I’m just waking up so some of it might just be that. :rofl:

No Bootstrap rant here… (not early, and I like Bootstrap) :slight_smile:

Anyways…

I didnt read to much (just skimmed)…

BUT if the CONTENT output what you are looking to ‘filter’ (decide what gets output/displayed)

Seems like want to add in some criteria checking here:

while($sub_row = mysqli_fetch_array($product_result)) {
    //add check here

Perhaps something like:

while($sub_row = mysqli_fetch_array($product_result)) {
    //add check here
    if($row["ordered_date"] == '2021-09-09'){
        //output display content here now

I would of course figure out some way that works for your project to dynamically updater this line of course:

if($row["ordered_date"] == '2021-09-09'){

So that the date isnt ‘hard-coded’… (set a hidden $_POST value/field or something?)

good luck…

Or just do as I do and run a separate query for each tab go get all your data just for that one tab.

can you give me some tips on how you do it? I’m new to this and want to learn something about it. thanks!

Well, yes, but, this post will be gone in 24 hours, less actually now since you dumped it.
I am gone for most of the next 12 hours. When get back, I will post an example for you.
By the way, I like bootstrap for a lot of reasons. It makes design of the page easier.
( It does not help with the PHP parts, but, combined they make a nice display. )
Read up on Whisper’s and Strider’s comments and that might help you get started.

Alight! Thank you for willing to get back to me!

Sponsor our Newsletter | Privacy Policy | Terms of Service