0

i have 3 table T1, T2, T3,
so, in T1 i want to select 1st row and select from T2 the rows related to the row selected in T1, and select from T3 rows related to T2 how have relation with row selected in T1 and print all this in one continer withe php while loop function see the images for more descriptions

img1

Img2

2 Answers 2

0

Base on what I understand with your question. This could be the answer

<?php
$db = new PDO("mysql:host=localhost", "username", "password");

$q1 = $db->prepare("SELECT * FROM T1");
$q1->execute();
$f1 = $q1->fetchAll(PDO::FETCH_ASSOC);
foreach ($f1 as $f1_items) {
    echo "<tr><td>".$f1['id_cat']."</td></tr>";
    $q2 = $db->prepare("SELECT * FROM T2 WHERE id_cat = ".$f1['id_cat'].";");
    $q2->execute();
    $f2 = $q2->fetchAll(PDO::FETCH_ASSOC);
    foreach ($f2 as $f2_items) {
        echo "<tr><td>\t".$f2['id_tr']."</td></tr>";
        $q3 = $db->prepare("SELECT * FROM T3 WHERE id_tr = ".$f2['id_cus'].";");
        $q3->execute();
        $f3 = $q3->fetchAll(PDO::FETCH_ASSOC);
        foreach ($f3 as $f3_items) {
            echo "<tr><td>\t\t".$f2['id_cus']."</td></tr>";
        }
    }
}
?>
Sign up to request clarification or add additional context in comments.

3 Comments

If you find this solution alike to your solution, you can mark this as the answer. However, if it's not you may post your own answer and also mark it as the answer
i can not accept my own answer !! how can i set my own answer as the solution of this question
just answer your question then
0

Solved and this is the code i am happy :)

    $ReqFindRows = "SELECT * FROM commandes WHERE commande_status = 0 AND date(commande_le) = CURDATE()";
$STMTFindRows = $connect->stmt_init();
if(!$STMTFindRows->prepare($ReqFindRows)){
echo "No Results";
}
else {
$STMTFindRows->execute();
$ResultsFindRows = $STMTFindRows->get_result();
$x = 0;
while($ArrayCat = $ResultsFindRows->fetch_assoc()){ 
switch($ArrayCat['commande_importance']){
case 0 : 
$importance = 'Normal';
$bgclas = "bg-blue";
break;
case 1 : 
$importance = 'Urgent';
$bgclas = "bg-yellow";
break;
case 2 : 
$importance = 'Immediat';
$bgclas = "bg-red";
break;
};
$prods = array();   
$GetProductsInCommandeQuery = "SELECT * FROM commandes_produits WHERE commande_id = ?";             
$GetProductsInCommandeSTMT = $connect->stmt_init();
if(!$GetProductsInCommandeSTMT->prepare($GetProductsInCommandeQuery)){
echo $connect->error;
}
else {
$id_toserch = $ArrayCat["commande_id"];
$GetProductsInCommandeSTMT->bind_param("s", $id_toserch );
$GetProductsInCommandeSTMT->execute();
$GetProductsInCommandeResults = $GetProductsInCommandeSTMT->get_result();
$Prodss = "";
while($GetProductsInCommandeArray = $GetProductsInCommandeResults->fetch_array()){
$prods = $GetProductsInCommandeArray["recette_id"];
$GetSupQuery = "SELECT * FROM commandes_supp WHERE tr_number = ? AND commande_id = ?";
$GetSupSTMT = $connect->stmt_init();
if(!$GetSupSTMT->prepare($GetSupQuery)){
echo $connect->error;
}
else {
$trNumber = $GetProductsInCommandeArray["tr_number"];
$GetSupSTMT->bind_param("ss", $trNumber, $id_toserch );
$GetSupSTMT->execute();
$GetSupResults = $GetSupSTMT->get_result();
$Supp = "";
while($GetSupArray = $GetSupResults->fetch_array()){
$Suppss = $GetSupArray["supp_id"];
$Supp .= '<p style="color:#F00">'.$Suppss.' </p>';
}
}
$Prodss .=  
'<tr>
<td>
'.$prods.'
'.$Supp.'
</td>
<td>
A table
</td>
<td>
<button type="button" class="btn btn-sm">Servis</button>
</td>
</tr>   ';                                  
}
}                   
?>
                    <div class="col-xs-6 col-md-4" style="margin-bottom:10px;">
                      <div class="tiket">
                        <div class="tikeheader <?php echo $bgclas ?>">
                          <span class="commandenumber">
                            <i class="fa fa-star iconheader">
                            </i>
                            <?php echo $ArrayCat["commande_id"] ?> A Table
                          </span>
                          <span class="importance">
                            <?php echo $importance?>
                          </span>
                        </div>
                        <div class="tiketbody">
                          <table  class="tiketbodytable">
                            <tbody>
                              <?php echo $Prodss ?>
                            </tbody>
                          </table>
                        </div>
                      </div>
                    </div>  
                    <?php               
}
}
?>                      
                  </div>
                </div>
              </div>
            </div>
            <?php   
}
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.