Jump to content

sashavalentina

Members
  • Posts

    43
  • Joined

  • Last visited

Posts posted by sashavalentina

  1. 35 minutes ago, requinix said:

    That does not help to explain why you're doing this. I'm asking because this query

    
    INSERT INTO invoice_price (order_id) SELECT order_id FROM ordered_items GROUP BY order_id WHERE order_id = '$order_id'

    doesn't make any sense: you take the $order_id that you already know, search for it in the ordered_items table, and then insert those results into invoice_price? Why aren't you inserting the $order_id value directly just like you did with ordered_items?

    Because i wanted to group the order_id into another table. Which i have no idea how should i do it. If i do it like the one i did with the ordered_items table, the order_id will be saved in the database saperately into my invoice_price table. I want the order_id to be saved in groups. Can i know is there any way i can do that?

     

     

  2. I have a system that saves the user purchase into a table called ordered_items. Where the purchase data will be saved into this table if the product stock available is more than the quantity that the user intended to purchase. The way how the system saved the data is by id. Which means if the USER A bought one iPad, two iPhone , USER B bought one AirPods, Iphone and an Ipad, USER C bought three IMac, two Macbook. The data that store in the table will look like this 

    image.png.95b94a97d353f5e17bf257bef08a9132.png

    Now I created another table called the invoice_price table where i want the above data to be group according to the order_id in the ordered_items table. So after the table is grouped, the data saved in the database will look something like this

    image.png.a82d602c19efaaee5d7e2016411acbaf.png

    I tried the below sql but it does not work. Does anyone knows what can i do to achieve what I described above?

     if($product_stocks >= $quantity) {
              $osql = "INSERT INTO `ordered_items`(`order_id`, `user_id`, `seller_id`, `product_id`, `quantity`, `purchase_price`) 
              VALUES ('$order_id', '$user_id', '$seller_id', '$product_id', '$quantity', '$purchase_price')";
              if($conn->query($osql)) {
                  $product_name = $row['cart_name'];
                  $cn_product_name = $row['cn_cart_name'];
                  $m_product_name = $row['m_cart_name'];
                  $nsql = "INSERT INTO `notifications`(`notification_title`,`cn_notification_title`,`m_notification _title`, `notification_date`, `notification_text`,`cn_notification_text`,`m_notification_text`, `user_id`, `seller_id`, `order_id`, `product_id`, `user_notify`, `seller_notify`, `admin_notify`) 
                  VALUES 
                  ('New $order_type ','新订单','Pesanan Baharu', '$now', '<b>Order No: #$order_id</b><br>$order_type for $quantity $product_name is Placed Successfully', '<b>订单号: #$order_id</b><br>已成功下单 $quantity 的 $cn_product_name ', 
                  '<b>Nombor Pesanan: #$order_id</b><br>Pesanan untuk  $quantity $m_product_name anda sudah berjaya ', '$user_id', '$seller_id', '$order_id', '$product_id', 0, 0, 0)";
                 
                  if($conn->query($nsql)){
                     $discountsql = "INSERT INTO invoice_price (order_id) SELECT order_id FROM ordered_items GROUP BY order_id WHERE order_id = '$order_id'";
                      $conn->query($discountsql);
                  }
              }

     

  3. As i can't use css to make my auto numbering for my tables with css using TCPDF.I'm trying to use Javascipt to make this work. I read the documentation this and this on how to add javascript into my tcpdf. But i do not know why it does not work and it shows the error of Parse error: syntax error, unexpected 'var' (T_VAR) in C:\filepath\XAMPP\htdocs\filepath\customerinvoice.php on line 211 Can i know how can i define my 'var' in tcpdf? Or is not possible to add javascript in TCPDF? Please help me with this issue. Any help will be apprecialted. Thanks in advance 

    This are my codes

     

       $htmlcontent .='
    <table cellpadding="7" style="max-height: 1000px;">
        <tr class="receiptcontent">
        <td style="font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
    
        </td>
    
            <td width= "30%" colspan="3" style="font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
                '.$irow['product_name'].'
            </td>
            
             <td style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
               '.$irow['product_code'].'
            </td>
             <td width= "15%" style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
               '.$irow['quantity'].' '.$irow['quantity_unit'].'
            </td>
             <td  width= "15%" style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
              RM '.$irow['original_price'].'
            </td>
            <td  width= "20%" style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
                RM '.$irow['price'].'
            </td>
        </tr>
    </table>
    
    ';
    }

    This is the javascript i added in to implement auto numbering for my tables

     

    $js = 
    var table = document.getElementsByTagName('table')[0],
      rows = table.getElementsByTagName('tr'),
      text = 'textContent' in document ? 'textContent' : 'innerText';
    
    for (var i = 0, len = rows.length; i < len; i++) {
      rows[i].children[0][text] = i + ': ' + rows[i].children[0][text];
    };
        
    // Add Javascript code
    $pdf->IncludeJS($js);
        $pdf->writeHTML($htmlcontent);  
        ob_end_clean(); 
        $pdf->Output('customerinvoice.pdf', 'I');

     

  4. I wanted to do auto numbering for my tables with css using TCPDF. I tried both ways but it does not work at all.

    I tried the one in the documentation of tcpdf and it does not work too. Can anyone give me a piece of advice on how to make this work? 

    These are the both ways i mentioned and it did not work. 

        $htmlcontent .='
        <style>
        table {
    		  counter-reset: rowNumber;
    		}
    
    		table tr::before {
    		  display: table-cell;
    		  counter-increment: rowNumber;
    		  content: counter(rowNumber) ".";
    		  padding-right: 0.3em;
    		  text-align: right;
    		}
        </style>
        <table id="receiptTable" cellpadding="3" style="max-height: 1000px;">
            <tr>
             <td width = "7%"style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
                   
                </td>
            
                <td colspan="3" style="font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
                    '.$irow['product_title'].'
                </td>
                
                 <td style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
                   '.$irow['product_sku'].'
                </td>
                 <td style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
                   '.$irow['quantity'].' '.$irow['quantity_unit'].'
                </td>
                 <td style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
                  RM '.$irow['product_buy_price'].'
                </td>
                <td  width= "20%" style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
                    RM '.$irow['purchase_price'].'
                </td>
            </tr>
        </table>
    
        ';
        }

    for this i use the method of including external css into my tables but it does not work as well. I did make sure my file path is correct. (the code below)
     

     $htmlcontent .='
        <style>.file_get_contents(css/receipt.css).</style>
        <table id="receiptTable" cellpadding="3" style="max-height: 1000px;">
            <tr>
             <td width = "7%"style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
                   
                </td>
            
                <td colspan="3" style="font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
                    '.$irow['product_title'].'
                </td>
                
                 <td style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
                   '.$irow['product_sku'].'
                </td>
                 <td style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
                   '.$irow['quantity'].' '.$irow['quantity_unit'].'
                </td>
                 <td style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
                  RM '.$irow['product_buy_price'].'
                </td>
                <td  width= "20%" style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;">
                    RM '.$irow['purchase_price'].'
                </td>
            </tr>
        </table>
    
        ';
        }

     

  5. I use AJAX method to get the value for `$month` from the year-month selection in my page.  The year-month is pass correct correctly when it gets into my PHP code. But i am not sure how do i get the value and use it for my sql condition. 

    I'm trying to plot a graph using Chart JS according to the year-month selection from the user. when the user select "2021-03" all the order that is made in the month of March will be plotted into the graph. There's no data shown in my page now and i do not know how can i query it. Can anyone enlighten me how can i do it? Because i do not know what mistake did i made here. Any kind of explanation will be appreciated. Thanks!

     

    This is the code that i use for year-month selection 

    <div class="col-2 my-auto">
                    <input type="month" id="month" class="form-control" value="<?php echo date('Y-m'); ?>">
                  </div>
    
                   <div class="col-2 my-auto">
                    <button type="button" class="btn btn-info" onclick="loadchart();">
                      <i class="nc-icon nc-zoom-split"></i>
                    </button>
                  </div>

    This is the AJAX method

     <script type="text/javascript">
    function loadchart()
    {
     $('#spin1').show();
     var month= $('#month').val();
      var data = {    
        month: month,
      }
      $.ajax({
        method:"GET",
        data:data,
        url:"includes/loadchart.php",
        success:function(data)
        {
            $('#loadchart').html(data);
        }
      });
    
    }

    this is my loadchart.php

    <?php
    include '../session.php';
    if(isset($_GET['month']))
    {
        $months = $_GET['month'];
    ?>
    <?php
      $days = array();
      $gross_sales = array();
      $average_sales = array();
      $type = CAL_GREGORIAN;
      $month = date('n'); 
      $year = date('Y'); 
      $day_count = cal_days_in_month($type, $month, $year); 
      for ($i = 1; $i <= $day_count; $i++) {
          $sql = "SELECT *, SUM(purchase_price) as purchase_price FROM ordered_items WHERE DAY(order_datetime) = '$i' AND MONTH(order_datetime) = MONTH('".$months."') AND YEAR(order_datetime) = YEAR('".$months."') AND order_status = 5 ";
        $query = $conn->query($sql);
        $total = $query->num_rows;
        $row = $query->fetch_assoc();
        if($row['purchase_price'] != 0)
        {      
          $gross_sales[] = $row['purchase_price'];
        }
          
        else if ($row['purchase_price'] == 0 && $i <= date('d')) {
          $gross_sales[] = 0;
        }
    
        $average_sales[] =  $row['purchase_price'] / $day_count;
    
        $day =  $i.'/'.$month; 
        array_push($days, $day);
      }
    
      $days = json_encode($days);
      $daily_gross_sales = json_encode($gross_sales);
      $average_gross_sales =  json_encode($average_sales);
    ?>
      <script>
        const colors = {
          colorcode: {
            fill: '#51cbce',
            stroke: '#51cbce',
          },
        };
        var ctx2 = document.getElementById("attChart").getContext("2d");
        const attChart = new Chart(ctx2, {
          type: 'line',
          data: {
            labels: <?php echo $days; ?>,
            datasets: [{
              label: "Gross Sales: RM",
              fill: true,
              pointBackgroundColor: colors.colorcode.stroke,
              borderColor: colors.colorcode.stroke,
              pointHighlightStroke: colors.colorcode.stroke,
              borderCapStyle: 'dot',
              pointRadius: 5,
              pointHoverRadius: 5,
              pointStyle: 'dot',
              data: <?php echo $daily_gross_sales; ?>,
              showLine: true
            },
            {
              label: "Average Sales: RM",
              fill: true,
              pointBackgroundColor:   '#FF0000',
              borderColor: ' #FF0000 ',
              pointHighlightStroke: '#FF0000',
              borderCapStyle: 'dot',
              pointRadius: 5,
              pointHoverRadius: 5,
              pointStyle: 'dot',
              data: <?php echo $average_gross_sales; ?>,
              showLine: true
        }
            ]
          }
        <?php   
    }
    ?>

    I do not know why my query from the loadchart.php is incorrect. Please help me with this advice me on this issue thanks!

      $sql = "SELECT *, SUM(purchase_price) as purchase_price FROM ordered_items WHERE DAY(order_datetime) = '$i' AND MONTH(order_datetime) = MONTH('".$months."') AND YEAR(order_datetime) = YEAR('".$months."') AND order_status = 5 ";

     

  6. I'm creating a line graph using ChartJs. I wanted to display my data according to the month selected by the user. For example, if the user select "2021-03" all the order that is made in the month of March will be plotted in the graph. It works well for the current month, but it does not work for the selected month. 

    I use Ajax to get the data but i do not know why my graph does not shown when i click on my `loadchart();` button. Can anyone enlighten me how can i do it? Because i do not know what mistake did i made here. Any kind of explanation will be appreciated. Thanks!

     

    This is the where i place my `loadchart()` button and also the javascript to plot the graph.

      <div class="col-md-12 form-group">
                <div class="card" style="box-shadow: 0 0 8px rgb(0,0,0,0.3)">
                    <div class="row">
                       <div class="col col-lg-1"></div>
                      <div class="col-2 my-auto">
                        <input type="month" id="month" class="form-control" value="<?php echo date('Y-m'); ?>">
                      </div>
    
                       <div class="col-2 my-auto">
                        <button type="button" class="btn btn-info" onclick="loadchart();">
                          <i class="nc-icon nc-zoom-split"></i>
                        </button>
                      </div>
                    </div>
                    <div id="loadchart">
                  <h6 class="text-muted text-center p-3"><i class="fa fa-line-chart"></i> Daily Gross Sales (Current Month)</h6>
                  <div  class="card-body">
                    <canvas id="attChart"></canvas>
                  </div>
                </div>
                </div>
              </div>
    
            </div>
          </div>
          
        </div>
      </div>
      
      <!-- Chart JS -->
      <script src="./assets/js/plugins/chartjs.min.js"></script>
      <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
      <?php
      $days = array();
      $gross_sales = array();
      $average_sales = array();
    
      $type = CAL_GREGORIAN;
      $month = date('n'); // Month ID, 1 through to 12.
      $year = date('Y'); // Year in 4 digit 2009 format.
      $day_count = cal_days_in_month($type, $month, $year); // Get the amount of days
    
      //loop through all days
      for ($i = 1; $i <= $day_count; $i++) {
        $sql = "SELECT *, SUM(purchase_price) as purchase_price FROM ordered_items WHERE DAY(order_datetime) = '$i' AND MONTH(order_datetime) = MONTH(NOW()) AND YEAR(order_datetime) = YEAR(NOW()) AND order_status = 5 ";
        $query = $conn->query($sql);
        $total = $query->num_rows;
        $row = $query->fetch_assoc();
    
          
        if($row['purchase_price'] != 0)
        {      
          $gross_sales[] = $row['purchase_price'];
        }
          
        else if ($row['purchase_price'] == 0 && $i <= date('d')) {
          $gross_sales[] = 0;
        }
    
        $average_sales[] =  $row['purchase_price'] / $day_count;
    
        $day =  $i.'/'.$month; //format date
        array_push($days, $day);
      }
    
      $days = json_encode($days);
      $daily_gross_sales = json_encode($gross_sales);
      $average_gross_sales =  json_encode($average_sales);
    
    ?>
      <script>
        const colors = {
          colorcode: {
            fill: '#51cbce',
            stroke: '#51cbce',
          },
        
        };
        var ctx2 = document.getElementById("attChart").getContext("2d");
        const attChart = new Chart(ctx2, {
          type: 'line',
          data: {
            labels: <?php echo $days; ?>,
            
            //labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
            datasets: [{
              label: "Gross Sales: RM",
              fill: true,
              //backgroundColor: colors.colorcode.fill,
              pointBackgroundColor: colors.colorcode.stroke,
              borderColor: colors.colorcode.stroke,
              pointHighlightStroke: colors.colorcode.stroke,
              borderCapStyle: 'dot',
              pointRadius: 5,
              pointHoverRadius: 5,
              pointStyle: 'dot',
              data: <?php echo $daily_gross_sales; ?>,
              showLine: true
            },
            {
              label: "Average Sales: RM",
              fill: true,
              //backgroundColor: colors.colorcode.fill,
              pointBackgroundColor:   '#FF0000',
              borderColor: ' #FF0000 ',
              pointHighlightStroke: colors.colorcode.stroke,
              borderCapStyle: 'dot',
              pointRadius: 5,
              pointHoverRadius: 5,
              pointStyle: 'dot',
              data: <?php echo $average_gross_sales; ?>,
              showLine: true
            }
    
            ]
          },
    
          options: {
            responsive: true,
            
            // Can't just just `stacked: true` like the docs say
            scales: {
              yAxes: [{
                stacked: false,
                gridLines: {
                  display: true,
                  color: "#dee2e6"
                },
                ticks: {
                  stepSize: 100000,
                  callback: function(tick) {
                    return 'RM'+tick.toString();
                  }
                }
              }],
              
              xAxes: [{
                stacked: false,
                gridLines: {
                  display: false
                },
              }]
              
            },
            animation: {
              duration: 3000,
            },
            
            legend:{
              display: false,
            }
          }
        });
      </script>

    This is my AJAX method 

       <script type="text/javascript">
        function loadchart()
        {
         $('#spin1').show();
         var month= $('#month').val();
         //alert(date);
          var data = {     // create object
            month: month,
            
          }
          $.ajax({
            method:"GET",
            data:data,
            url:"includes/loadchart.php",
            success:function(data)
            {
                $('#loadchart').html(data);
            }
          });
    
        }
      </script>

    This is where i use to load the graph whenever a month is selected. (loadchart.php)

    <?php
    include '../session.php';
    if(isset($_GET['month']))
    {
    	$months = $_GET['month'];
    ?>
    
     <h6 class="text-muted text-center p-3"><i class="fa fa-line-chart"></i> Daily Gross Sales (<?php echo $months ?>)</h6>
                  <div id="loadchart" class="card-body">
                    <canvas id="attChart"></canvas>
                  </div>
                </div>
              </div>
    
            </div>
          </div>
          
        </div>
      </div>
      
      <!-- Chart JS -->
      <script src="./assets/js/plugins/chartjs.min.js"></script>
      <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    
      <?php
      $days = array();
      $gross_sales = array();
      $average_sales = array();
    
      $type = CAL_GREGORIAN; // Gregorian (localized) calendar
      $month = date('n'); // Month ID, 1 through to 12.
      $year = date('Y'); // Year in 4 digit 2009 format.
     
      $day_count = cal_days_in_month($type, $month, $year); // Get the amount of days
    
      //loop through all days
      for ($i = 1; $i <= $day_count; $i++) {
          $sql = "SELECT *, SUM(purchase_price) as purchase_price FROM ordered_items WHERE DAY(order_datetime) = '$i' AND MONTH(order_datetime) = MONTH('".$months."') AND YEAR(order_datetime) = YEAR('".$months."') AND order_status = 5 ";
        $query = $conn->query($sql);
        $total = $query->num_rows;
        $row = $query->fetch_assoc();
    
          
        if($row['purchase_price'] != 0)
        {      
          $gross_sales[] = $row['purchase_price'];
        }
          
        else if ($row['purchase_price'] == 0 && $i <= date('d')) {
          $gross_sales[] = 0;
        }
    
        $average_sales[] =  $row['purchase_price'] / $day_count;
    
        $day =  $i.'/'.$month; //format date
        array_push($days, $day);
      }
    
      $days = json_encode($days);
      $daily_gross_sales = json_encode($gross_sales);
      $average_gross_sales =  json_encode($average_sales);
    
    ?>
      <script>
        const colors = {
          colorcode: {
            fill: '#51cbce',
            stroke: '#51cbce',
          },
        
        };
        var ctx2 = document.getElementById("attChart").getContext("2d");
        const attChart = new Chart(ctx2, {
          type: 'line',
          data: {
            labels: <?php echo $days; ?>,
            
            //labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
            datasets: [{
              label: "Gross Sales: RM",
              fill: true,
              //backgroundColor: colors.colorcode.fill,
              pointBackgroundColor: colors.colorcode.stroke,
              borderColor: colors.colorcode.stroke,
              pointHighlightStroke: colors.colorcode.stroke,
              borderCapStyle: 'dot',
              pointRadius: 5,
              pointHoverRadius: 5,
              pointStyle: 'dot',
              data: <?php echo $daily_gross_sales; ?>,
              showLine: true
            },
            {
              label: "Average Sales: RM",
              fill: true,
              //backgroundColor: colors.colorcode.fill,
              pointBackgroundColor:   '#FF0000',
              borderColor: ' #FF0000 ',
              pointHighlightStroke: '#FF0000',
              borderCapStyle: 'dot',
              pointRadius: 5,
              pointHoverRadius: 5,
              pointStyle: 'dot',
              data: <?php echo $average_gross_sales; ?>,
              showLine: true
            }
    
            ]
          },
    
          options: {
            responsive: true,
            
            // Can't just just `stacked: true` like the docs say
            scales: {
              yAxes: [{
                stacked: false,
                gridLines: {
                  display: true,
                  color: "#dee2e6"
                },
                ticks: {
                  stepSize: 100000,
                  callback: function(tick) {
                    return 'RM'+tick.toString();
                  }
                }
              }],
              
              xAxes: [{
                stacked: false,
                gridLines: {
                  display: false
                },
              }]
              
            },
            animation: {
              duration: 3000,
            },
            
            legend:{
              display: false,
            }
          }
        });
      </script>
      
    <?php	
    }
    ?>

     

  7. I wanted to add class .tag on my image which is in the class .product-img. So i use the method of z-index. I style the z-index in my image tag but the .tag  is not overlapped on my .product-img. As shown in the image shown below. I do not know what mistake i did here. Any help will be appreciated thanks!

    image.png.f429e478b1729a4aa88a5f3010302cf4.png

    <?php 
         if ($preorder_stock == 0){
          echo" <img id='productimg' class='product-img'  loading='lazy' src='../images/product-main/".$row['product_photo']."' > 
    
          <div id='circle'><p style='font-size:8px; padding-top:30%; text-align:center; ''>Pre Order</br> NOW</p> </div>
              
          " ;
         }else{
           echo" <img style='z-index:-1;' id='productimg' class='product-img'  loading='lazy' src='../images/product-main/".$row['product_photo']."' >
           <div class='tag' style='padding-top:20px;'>
                 <div id='circle'><p  style='font-size:8px; padding-top:30%; text-align:center; ''>Pre Order</br> NOW</p> </div>
                 </div>
    
           " ;
    
         }?>

     

  8. I'm trying to show my data under the toggle button according to the order_id. But i do not know why when i click on my toggle button it does not work. I do not know what is wrong with it. Any advice will be appreciated. 

      <?php
                       $dsql = "SELECT  o.order_id , o.purchase_price , o.order_datetime,  u.id, u.user_fullname ,  p.id, p.product_title , c.id , c.category, s.id , s.seller_fullname FROM ordered_items o INNER JOIN users u ON o.user_id = u.id INNER JOIN sellers s ON o.seller_id = s.id 
                          INNER JOIN products p ON o.product_id = p.id CROSS JOIN category c ON p.product_category = c.id WHERE category = '".$category."' ORDER BY o.order_id DESC";
                          $dquery = $conn->query($dsql);
                          $tot_orders = mysqli_num_rows($dquery);
                          if (!mysqli_num_rows($dquery)) {
                            echo '
                              <div class="col-12">
                                <div class="badge badge-danger">No Orders Found</div>
                              </div>
                            ';
                          } else {
                            while ($drow = $dquery->fetch_assoc()) {
                              ?>
                                    <tr>
                                      <td>
                                        #<?php echo $drow['order_id']; ?>
                                      </td>
                                      <td>
                                        <?php echo $drow['user_fullname']; ?>
                                      </td>
                                      <td>
                                        RM<?php echo  number_format($drow['purchase_price'],2); ?>
                                      </td>
                                     
                                      <td class="text-center">  
                                      <a style="text-decoration: none;color: #000;" title="View Details" data-toggle="collapse" data-target="#products-details<?php echo $drow['order_id']; ?>">
                                      <i class="nc-icon nc-minimal-down" onclick="changeToggleIcon(this)"></i>
                                  </a>  
                            </td>        
                                      </td>
                                    </tr>
              
                                 
                                    
    
                            <?php   
                               $p_sql = "SELECT  o.order_id , o.purchase_price , o.order_datetime , o.quantity , o.quantity_unit, u.id, u.user_fullname ,  p.id, p.product_title , p.product_photo , c.id , c.category, s.id , s.seller_fullname FROM ordered_items o INNER JOIN users u ON o.user_id = u.id INNER JOIN sellers s ON o.seller_id = s.id 
                          INNER JOIN products p ON o.product_id = p.id CROSS JOIN category c ON p.product_category = c.id WHERE category = '".$category."'" ;
                            $p_query = $conn->query($p_sql);
                            while ($p_row = $p_query->fetch_assoc()) {
                          ?>      
                            <tr class="collapse" id="products-details<?php echo $drow['order_id']; ?>" >
                               <td style="border-top: none; font-size: 10px;">
                              <img src="https://dev.gopasar.today/images/product-main/<?php echo $p_row['product_photo']; ?>" style="height: 50px; width: 50px;">
                            </td>
                              <th style="border-top: none; font-size: 10px;">
                                
                                <?php echo $p_row['product_title']; ?>
                              </th>
                              <th style="border-top: none; font-size: 10px;">
                                Order Quantity :<?php echo $p_row['quantity']; ?><?php echo $p_row['quantity_unit']; ?>
                              </th>
                              <th style="border-top: none; font-size: 10px;">
                                  RM   <?php echo $p_row['purchase_price'];?>
                                 
                              </th>
    
                            </tr>
                            
    
                         
                        </div>
              
                </div>
              </div>
    <?php
    }
    }
    }
    
    ?>

     

  9. I want to make display my data into tables but why does it not shown in the table? the total results shown 1 but i only got no data display in my table. Can i know what is wrong in my code? Is there any mistake in my query?

    <?php
                $category = $_REQUEST['catid'];
                $month = $_REQUEST['month'];
                $sellerid = $_REQUEST['sellerid'];
                
                $sql = "SELECT  o.order_id , o.purchase_price , u.id, u.user_fullname ,  p.id, p.product_title , c.id , c.category, s.id , s.seller_fullname FROM ordered_items o INNER JOIN users u ON o.user_id = u.id INNER JOIN sellers s ON o.seller_id = s.id 
                INNER JOIN products p ON o.product_id = p.id CROSS JOIN category c ON p.product_category = c.id WHERE category = '".$category."' GROUP BY p.id ";
                $query = $conn->query($sql);
                $tot_orders = mysqli_num_rows($query);
                if (!mysqli_num_rows($query)) {
                  echo '
                    <div class="col-12">
                      <div class="badge badge-danger">No Orders Found</div>
                    </div>
                  ';
                } else {
                  while ($row = $query->fetch_assoc()) {
                    ?>
    
              <div class="col-12">
                <div class="card">
    
                  <div class="card-header">
                    <h4 class="card-title"> Report for category: <b> <?php echo $category ?> </b> ( <?php echo $month ?> ) from seller: <b> <?php echo $row['seller_fullname']; ?> </b></h4> 
                     <b class="float-left mb-4">Total Records: <?php echo $tot_orders; ?></b>
                  </div>
                    <div class="table-responsive" style="max-height: 70vh">
                      <table class="table">
                        <thead class="text-primary">
                          <th style=" position: sticky;top: 0; background: white";>
                            Order Id
                          </th>
                          <th style=" position: sticky;top: 0; background: white";>
                            User Name
                          </th>
                          <th style=" position: sticky;top: 0; background: white";>
                            Total Purchase
                          </th>
                          <th class="text-center" style=" position: sticky;top: 0; background: white";>
                            Action
                          </th>
                           
                        </thead>
                        <tbody>
                          <?php
                          if (!$tot_orders) {
                            echo '
                              <tr>
                                <td colspan="8" class="badge badge-danger">Nothing Found</td>
                              </tr>
                            ';
                          } else {
                             while ($row = $query->fetch_assoc()) {
                           
                             
                          ?>
                          <tr>
                            <td>
                              #<?php echo $row['order_id']; ?>
                            </td>
                            <td>
                              <?php echo $row['user_fullname']; ?>
                            </td>
                            <td>
                              RM<?php echo  number_format($row['purchase_price'],2); ?>
                            </td>
                          
                          </tr>
     </div>
              
                </div>
              </div>
        <?php
        
        }
        }
        }
        }
        
        ?>

    This is the result i got from my tables.There should be one data shown in the table when the Total Records:1. I do not know what mistake i did here. the result always display to be lack of one data from the Total Records

    image.png.5ef26560d5260689177388151c0a0843.png

     

  10. 4 minutes ago, kicken said:

    That's what's happening to your first row.  Every time you call fetch_assoc it returns the next row.  You call it here to return the first row, but don't ever echo that row data out in the table anywhere.  Remove that call and let your loop down below fetch the first row.

    Since it looks like you're calling it there so you can get the seller name, you'll have to come up with an alternative way to obtain that information or re-arrange your code so you can get the name and all the row data.

    Can i know what is the other way to obrain my data other than fetch_assoc? Because this is the only method i know.

  11. This is my ordered items table

    image.thumb.png.d7eb2587e0397062251ccba2a4719be5.png

    This is my products table

    image.png.f7c22c94dd639fe79995529010cf6c46.png

    This is my user table

    image.png.bec82d421ee74fad29b7ddace4598dd4.png

    This is my seller table

    image.png.eefaeaa6b8d43b8321b7cd69dbb3cded.png

    This is my category table

    image.png.bd2fbe5695bd360ebd86ee9ba117cff7.png

    I want to display the order_id, user_fullname and purchase_price, seller_fullname. I wrote the query below i got queried results in the phpmyadmin page, but when i want it to display in my page, the first result does not show, but instead it shows the follwing results after the first one. If there's only one data in that category, there will be no result display in my page. I do not know what is wrong with my query that cause this. This is the sql query that i use

     $sql = "SELECT *, o.order_id , o.purchase_price , u.id, u.user_fullname ,  p.id, p.product_title , c.id , c.category, s.id , s.seller_fullname FROM ordered_items o 
        INNER JOIN users u ON o.user_id = u.id 
        INNER JOIN sellers s ON o.seller_id = s.id 
        INNER JOIN products p ON o.product_id = p.id 
        INNER JOIN category c ON p.product_category = c.id WHERE c.category = '".$category."' ";

    The $category, $month and $seller_id are the values that are pass from the previous page. (Which i already check, the value pass are all correct)

    These are the codes that i use to display the data in my page

     

    <?php
           $category = $_REQUEST['catid'];
            $month = $_REQUEST['month'];
            $sellerid = $_REQUEST['sellerid'];
            
            $sql = "SELECT *, o.order_id , o.purchase_price , u.id, u.user_fullname ,  p.id, p.product_title , c.id , c.category, s.id , s.seller_fullname FROM ordered_items o INNER JOIN users u ON o.user_id = u.id INNER JOIN sellers s ON o.seller_id = s.id INNER JOIN products p ON o.product_id = p.id INNER JOIN category c ON p.product_category = c.id WHERE c.category = '".$category."' ";
            $query = $conn->query($sql);
            $tot_orders = mysqli_num_rows($query);
            if (!mysqli_num_rows($query)) {
              echo '
                <div class="col-12">
                  <div class="badge badge-danger">No Orders Found</div>
                </div>
              ';
            } else {
              $row = $query->fetch_assoc();
          ?>
    
          <div class="col-12">
            <div class="card">
    
              <div class="card-header">
                <h4 class="card-title"> Report for category: <b> <?php echo $category ?> </b> ( <?php echo $month ?> ) from seller: <b> <?php echo $row['seller_fullname']; ?> </b></h4> 
                 <b class="float-left mb-4">Total Records: <?php echo $tot_orders; ?></b>
              </div>
                <div class="table-responsive" style="max-height: 70vh">
                  <table class="table">
                    <thead class="text-primary">
                      <th style=" position: sticky;top: 0; background: white";>
                        Order Id
                      </th>
                      <th style=" position: sticky;top: 0; background: white";>
                        User Name
                      </th>
                      <th style=" position: sticky;top: 0; background: white";>
                        Total Purchase
                      </th>
                      <th class="text-center" style=" position: sticky;top: 0; background: white";>
                        Action
                      </th>
                       
                    </thead>
                    <tbody>
                      <?php
                      if (!$tot_orders) {
                        echo '
                          <tr>
                            <td colspan="8" class="badge badge-danger">Nothing Found</td>
                          </tr>
                        ';
                      } else {
                       
                        while ($row = $query->fetch_assoc()) {
                         
                      ?>
                      <tr>
                        <td>
                          #<?php echo $row['order_id']; ?>
                        </td>
                        <td>
                          <?php echo $row['user_fullname']; ?>
                        </td>
                        <td>
                          RM<?php echo  number_format($row['purchase_price'],2); ?>
                        </td>
                         <td>
                              <a style="text-decoration: none;color: #000;" title="View Details" data-toggle="collapse" data-target="#products-details<?php echo $row['id']; ?>">
                                  <i class="nc-icon nc-minimal-down" onclick="changeToggleIcon(this)"></i>
                              </a>  
                        </td>
                        <td class="text-center">          
                        </td>
                      </tr>

    This is the result i got from php myadmin

    image.png.18a88ee0e14a94300893477207c2a9f0.png

    This is the result i got from my page

    image.png.34954f3845d6880ff695df8f8a819b53.png

    I do not know why the result does not show as the one in phpmy admin in my page. Can i know what mistake did i made? is it the mistake i made in my query or the codes that i use to display it in my page? any help will be appreciated thank you so much

  12. I have 3 tables which are order tables , product tables and category_tables .

    image.png.530010fe83840f6a46da5bea1d63593d.png

    I want to get the result of the category Meat only from the order_tables by cross joining it with the product tables and the category_tables . But why do i always get the result of the first product with the category i selected. This is the sql i use to select the Meat category

    SELECT * FROM ( (SELECT * FROM order_table) as yw1 INNER JOIN (SELECT * FROM products) as yw2 ON yw1.product_id = yw2.id CROSS JOIN (SELECT * FROM category) as yw5 ON yw2.product_category = yw5.id) GROUP BY category = "Meat"

    For example, i selected the Meat category it will show the result of

    | id | order_id | product_id | product_name | id | category_name |
    | 1 | 10001      | 1                 | carrot                | 1 |      Tubers           |
    | 4 | 10004     | 4                 | Beef                 | 4 |      Meat              |

  13. I have this function where i want to pass the month and year according to the date drop down that is chosen by the user. But can't seem to get the selected month and year. But instead, i got the month and year for now (which is April 2020). Can any one show me how can i achive this? I mean how can i pass the month and year selected to my `allreport-summary.php` page. It would be better if you guys can show me examples of codes on how can i implement this. Any help will be appreciated. Thank you so much. cheers! 


       

      <div class="row">
                      <div class="col-4 my-auto">
                        <input type="month" id="month" class="form-control" value="<?php echo date('Y-m'); ?>">
                      </div>
                      <div class="col-4 my-auto">
                        <select class="form-control" id="seller">
                          <option value="">Select All</option>
                          <?php
                          $sql = "SELECT * FROM sellers ORDER BY seller_registered";
                          $query = $conn->query($sql);
                          while ($row = $query->fetch_assoc()) {
                          ?>
                          <option value="<?php echo $row['id'];?>"><?php echo $row['seller_fullname'];?></option>
                          <?php } ?>
                        </select>
                     
                      </div>
                      <div class="col-4">
                        <button type="button" class="btn btn-info" onclick="loadreports();">
                          <i class="nc-icon nc-zoom-split"></i>
                        </button>
                      <a href="allreport-summary.php?month=<?php echo date('Y-m');?>">
                        <button type="button" class="btn btn-info" style="height: 40px;">
                          <i class="fa fa-file-excel-o"></i> &nbsp;  &nbsp;Export All Report
                        </button>
                       </a>
                          </div>


    how can i pass that `<a href="allreport-summary.php?month=<?php echo date('Y-m');?>">` according to the selection of `  <input type="month" id="month" class="form-control" value="<?php echo date('Y-m'); ?>">` ? 

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.