How to get each row value from the table using the id of the tbody [closed]

-3

I’ve been working for stock out inventory process which can search all item in the search bar and display in the table1 and click the item selected to enter the quantity want to deduct.

And display each data in table row to table2 selected by the user.

Anyone can help me with this? i just wanna know on how to get the each value in table2 to save in the database with name "tblstockout" and update those item quantity in "tblstock"

Thank you and regards

here’s my code:

<!--- html code to display the table1 and table 2-->
<!DOCTYPE html>
<html>
<head>
 
<body class="hold-transition sidebar-mini layout-fixed">
       <!--TABLE 1-->
      <div class="input-group"><div class="input-group-prepend"><span class="input-group-text" id="basic-addon1"><i class="fas fa-search"></i></span></div>
          <input class="form-control" type="text" placeholder="Product Search" aria-label="Search" id="search" name="search" onkeyup="loadproducts();"/>
        </div></div>
      <div id="product_area" class="table-responsive-sm table-wrapper-scroll-y my-custom-scrollbar" >
        <table class="table table-bordered table-striped" style="cursor: pointer;" id="table1">
          <thead>
            <tr class='text-center'>
              <td>Item Code</td>
              <td>Item description</td>
              <td>Unit</td>
              <td>Stocks</td>
            </tr>
            <tbody id="products">
            </tbody>
          </thead>
        </table>
      </div>
    </div>
    <!--TABLE 2-->
    <div id="content">
      <div id="price_column" class="table-responsive-sm table-wrapper-scroll-y my-custom-scrollbar-a">
        <form method="POST" action="">
        <table class="table table-bordered table-striped" style="cursor: pointer;" id="table2">
          <thead>
            <tr class='text-center'>
              <td>Item Code</td>
              <td>Item description</td>
              <td>Unit</td>
              <td>Quantity</td>
              <td>Action</td>
            </tr>
          </thead>
          <tbody id="tableData">
          </tbody>
        </table>
        </form>
      </div>
    </div>
  
        
  <!--Button to submit-->      
        <button style="float: left;" id="buttons" type="button" name='enter' class="Enter btn btn-secondary border"><i class="fas fa-handshake"></i> Finish</button>
   <!--Button to cancel-->         
        <button style="float: left;" id="buttons" type="button" class="cancel btn btn-secondary border"><i class="fas fa-ban"></i> Cancel</button>
      </div>
  

 </div>
  </div>
<!--JQuery to display data search by the user-->
  <?php include('templates/js_popper.php');?>
  <!--script function-->
  <script type="text/javascript" src="script.js"></script>
</body>
</html> 

<!----PHP code for the item_load.php to fetch product in the database-->

<?php
//database included//

    if (isset($_POST['products'])){

        $name = mysqli_real_escape_string($con,$_POST['products']);
        $show   = "SELECT * FROM tblstock WHERE item_desc LIKE '$name%' AND qnty > 0 OR id LIKE '$name%' AND qnty > 0";
        $query  = mysqli_query($con,$show);
        if(mysqli_num_rows($query)>0){
            while($row = mysqli_fetch_array($query)){
                echo "<tr class='js-add' data-barcode=".$row['id']." data-product=".$row['item_desc']." data-unit=".$row['unit'].">
                <td><center>".$row['id']."</td>
                <td>".$row['item_desc']."</td>";
                echo "<td><center>".$row['unit']."</center></td>";
                echo "<td><center>".$row['qnty']."</center></td>";
            }
        }
        else{
            echo "<td></td><td><center>No item found!</center></td><td></td><td></td>";
        }
    }?>
<script>
function loadproducts(){
    var name = $("#search").val();
    if(name){
        $.ajax({
            type: 'post',
            data: {
                products:name,
            },
            url: 'item_load.php',
            success: function (Response){
                $('#products').html(Response);
            }
        });
    }
};

//The script function to put quantity of each item_desc selected and add another row to the table2//

$('body').on('click','.js-add',function(){
        var target = $(this);
        var product = target.attr('data-product');
        var barcode = target.attr('data-barcode');
        var unit = target.attr('data-unit');    
        swal({
        title: "Enter Quantity:",
            content: "input",
          })
          .then((value) => {
              if (value == "") {
                  swal("Error","Entered none!","error");
              }else{
                  var qtynum = value;
                  if (isNaN(qtynum)){
                    swal("Error","Please enter a valid number!","error");
          }else if(qtynum == null){
            swal("Error","Please enter a number!","error");
              }else{
    
                    $('#tableData').append("<tr class='prd'><td class='barcode text-center'>"+barcode+"</td><td class='text-center'>"+product+"</td><td class='text-center'>"+unit+"</td><td class='qty text-center'>"+value+"</td><td class='text-center p-1'><button class='btn btn-danger btn-sm' type='button' id='delete-row'><i class='fas fa-times-circle'></i></button><tr>");
    
        }
            }
  });
});
</script>

$299 Affordable Web Design WordPress

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

How to get each row value from the table using the id of the tbody [closed]

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.