Goodevening everyone. I have combined two tables. For better understanding i made them smaller and changed descriptions to be easier.
lets call them A and B
A table has 3 columns
Id Name Car_Brands
1 Peter 1,2
2 John 1
3 Maria 3
B table has 3 columns
Id2 CarBrand Color
1 Fiat Red
2 Seat White
3 Audi Blue
Inside php, with the LEFT JOIN Command i have a table with 5 columns, all 3 of first table and Id2,CarBrand of second (if i query the SQL command its working fine)
$QueryTables = "SELECT A.Id,A.Name,A.Car_Brands,B.Id2,B.CarBrand
FROM A LEFT JOIN B ON A.Car_Brands = B.Id2";
mysqli_query($DbCon,"SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'");
$Results = mysqli_query($DbCon,$QueryTables);
Inside html i create a table to show the results
<tbody>
<?php while($CarsList = mysqli_fetch_assoc($Results)) { ?>
<tr>
<!-- Table Column Names -->
<td> Per.ID </td>
<td> Name </td>
<td> Car-Brand(s) </td>
<!-- Results -->
<td> <?php echo $Results["Id"]; ?>
<td> <?php echo $Results["Name"]; ?>
<td>
<!-- We have multiple possible cars to each owner so we make a loop check -->
<?php
$CarIDs = $Results["Car_Brands"];
$CarIDs = explode(',',$CarIDs);
$value = $CarsList["Id2"];
foreach($CarIDs as $value){
$Car = $CarsList['CarBrand'];
echo $Car;
echo "<br>";
?>
</td>
</tr>
</tbody>
What i see as a result is
Per.Id Name Car_Brand(s)
1 Peter Fiat
Fiat (<-i want to see here Seat)
2 John Fiat
3 Maria Audi
What am i doing wrong ? (PS I tried to simplify the question and the variables so forgive me for any fast transformation issues :) )