Skip to main content

forach 2 query in one Table side by side

the problem is i want to foreach 2 query inside one table .. but it doesn't work perfectly ..

first query reslut in array is :

Array ( [0] => Array ( [KODE_BRG] => YD-027 [NAMA_BRG] => CIMORY YD STRAW 70 ML BANDED 4 [OOS] => 17 [Available] => 2 [Total_Kunjungan] => 19 [Persen_OOS] => 89 ) 1 => Array ( [KODE_BRG] => YD-069 [NAMA_BRG] => CIMORY YD STRAWBERY MANGGO LF [OOS] => 38 [Available] => 5 [Total_Kunjungan] => 43 [Persen_OOS] => 88 ) 2 => Array ( [KODE_BRG] => YD-010 [NAMA_BRG] => CIMORY YD MIXED BERRIES 250 ML [OOS] => 54 [Available] => 8 [Total_Kunjungan] => 62 [Persen_OOS] => 87 ) [3] => Array ( [KODE_BRG] => YD-072 [NAMA_BRG] => CIMORY YD BANANA LF [OOS] => 37 [Available] => 6 [Total_Kunjungan] => 43 [Persen_OOS] => 86 ) [4] => Array ( [KODE_BRG] => YD-015 [NAMA_BRG] => CIMORY YD BLUEBERRY 250 ML [OOS] => 53 [Available] => 9 [Total_Kunjungan] => 62 [Persen_OOS] => 85 ) [5] => Array ( [KODE_BRG] => YD-028 [NAMA_BRG] => CIMORY YD BLUEBERRY 70 ML BND4 [OOS] => 16 [Available] => 3 [Total_Kunjungan] => 19 [Persen_OOS] => 84 ) [6] => Array ( [KODE_BRG] => YD-029 [NAMA_BRG] => CIMORY YD MIXED 70 ML BANDED 4 [OOS] => 16 [Available] => 3 [Total_Kunjungan] => 19 [Persen_OOS] => 84 ) [7] => Array ( [KODE_BRG] => YD-044 [NAMA_BRG] => YOLITE C+100 ORANGE [OOS] => 16 [Available] => 3 [Total_Kunjungan] => 19 [Persen_OOS] => 84 ) [8] => Array ( [KODE_BRG] => YD-045 [NAMA_BRG] => YOLITE C+100 ORIGINAL [OOS] => 16 [Available] => 3 [Total_Kunjungan] => 19 [Persen_OOS] => 84 ) [9] => Array ( [KODE_BRG] => YD-008 [NAMA_BRG] => CIMORY YD PLAIN 250 ML [OOS] => 51 [Available] => 11 [Total_Kunjungan] => 62 [Persen_OOS] => 82 ) )

the second query in array is :

Array ( [0] => Array ( [KODE_BRG] => YD-004 [Qty] => 379 ) 1 => Array ( [KODE_BRG] => YD-005 [Qty] => 347 ) 2 => Array ( [KODE_BRG] => YD-002 [Qty] => 240 ) [3] => Array ( [KODE_BRG] => YD-006 [Qty] => 211 ) [4] => Array ( [KODE_BRG] => YD-072 [Qty] => 127 ) [5] => Array ( [KODE_BRG] => YD-008 [Qty] => 126 ) [6] => Array ( [KODE_BRG] => YD-069 [Qty] => 121 ) [7] => Array ( [KODE_BRG] => YD-015 [Qty] => 101 ) [8] => Array ( [KODE_BRG] => YD-010 [Qty] => 82 ) [9] => Array ( [KODE_BRG] => YD-001 [Qty] => 72 ) )

there is 10 result inside both of query ..

and this is what i want to achieve:

lOOS --- SBQ ----
produk name from Query1 precentage Qty product from Query1 Product Code from Query2 Qty from Query2
..... ........ ........ ....
till 10th till 10th till 10th till 10th

and i tried many ways to achieve that but i didnt find the correct way to achieve it .

this is my the last try :

      <table style="width: 100%" >
    <thead>
      <tr style="border-bottom: 1px solid;">
        <th colspan=2><center>Out Of Stock</center></th>
        <th colspan=2><center>Sales By Qty</center></th>
      </tr>
    </thead>
    <tbody>
      <?php foreach ($OOS->result_array() as $key => $val1){?>
        <?php foreach ($SBQ->result_array() as $Kunci =>$val2) {?>
        <tr>
        <td width="200">
            <div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:33%"><?php echo $val1['NAMA_BRG'] ?>
            </div>
        </td>
        <td width="50"><?php echo $val1['Persen_OOS'] ?></td>
        <td><div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:33%"><?php echo $val2['KODE_BRG'] ?>
            </div>
        </td>
        <td width="50"><?php echo $val2['Qty'] ?></td>
      </tr>
      <?php }?>
      <?php }?>
    </tbody>
  </table>

but the result it looping every product 10 time and then moved to the second product .. here is the result of the last try :

enter image description here

and here is example by image of what i want to achieve :

enter image description here

can someone tell me where is my wrong code and help me acheive that and made my day



source https://stackoverflow.com/questions/67714057/forach-2-query-in-one-table-side-by-side

Comments

Popular posts from this blog

Where and how is this Laravel kernel constructor called? [closed]

Where and how is this Laravel kernel constructor called? public fucntion __construct(Application $app, $Router $roouter) { } I have read the documentation and some online tutorial but I can find any clear explanation. I am learning Laravel and I am wondering where does this kernel constructor receives its arguments from. "POSTMOTERM" CLARIFICATION: Here is more clarity.I have checked the boostrap/app.php and it is only used for boostrapping the interfaces into the container class. What is not clear to me is where and how the Kernel class is instatiated and the arguments passed to the object calling the constructor.Something similar to; obj = new kernel(arg1,arg2) or, is the framework using some magic functions somewhere? Special gratitude to those who burn their eyeballs and brain cells on this trivia before it goes into a full blown menopause alias "MARKED AS DUPLICATE". To some of the itchy-finger keyboard warriors, a.k.a The mods,because I believe in th...

Why is my reports service not connecting?

I am trying to pull some data from a Postgres database using Node.js and node-postures but I can't figure out why my service isn't connecting. my routes/index.js file: const express = require('express'); const router = express.Router(); const ordersCountController = require('../controllers/ordersCountController'); const ordersController = require('../controllers/ordersController'); const weeklyReportsController = require('../controllers/weeklyReportsController'); router.get('/orders_count', ordersCountController); router.get('/orders', ordersController); router.get('/weekly_reports', weeklyReportsController); module.exports = router; My controllers/weeklyReportsController.js file: const weeklyReportsService = require('../services/weeklyReportsService'); const weeklyReportsController = async (req, res) => { try { const data = await weeklyReportsService; res.json({data}) console...

How to show number of registered users in Laravel based on usertype?

i'm trying to display data from the database in the admin dashboard i used this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count(); echo $users; ?> and i have successfully get the correct data from the database but what if i want to display a specific data for example in this user table there is "usertype" that specify if the user is normal user or admin i want to user the same code above but to display a specific usertype i tried this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count()->WHERE usertype =admin; echo $users; ?> but it didn't work, what am i doing wrong? source https://stackoverflow.com/questions/68199726/how-to-show-number-of-registered-users-in-laravel-based-on-usertype