-4

I have two tables in my database and I want to get all usernames from table 1 where all usernames in my order table 2 and I have a 2 or 3 difficult ways to do it and it's very hard through fetch Data in a while loop if somebody can help to make it easy

So I think its so clear now in the sketch I want to see all username data from Table 2 if their username storge in table 2

thank you for helping.

enter image description here

<?php


$showUserOrder = array('ordered'=>'User 1','ordered'=>'User 2','ordered'=>'User 2');

$userwithorder = 'SELECT * FROM usersdata WHERE username = :ordered';
$sttmsosd = $pdo->prepare($userwithorder);
$sttmsosd->execute($showUserOrder);
$GetUserWithOrder =  $sttmsosd->fetchAll();



foreach($GetUserWithOrder as $gethasorder){
?>
<tr>
    <td class="col-md-1 info"># <?php echo $gethasorder['id'] ;?></td>
    <td class="col-md-1 info"><img src="../<?php echo $gethasorder['username'] ;?>" width="40" alt=""></td>
</tr>

<?php
}
?>
Dharman
  • 30,962
  • 25
  • 85
  • 135

1 Answers1

1

You can use a JOIN

SELECT
   table1.OrderID,
   table2.username
   ...
FROM
    table1
INNER JOIN
    table2 
    ON table1.orderUser = table2.username
kchason
  • 2,836
  • 19
  • 25