I cannot output data without duplicating a certain parameter from a many-to-one table.
I have a table that has four other tables linked to it :
contact_work | filial_work | department_work | position | number_work
contact_work :
<code>id | id_filial | id_department | id_position | full_name | email_user | id_number | tel_number
</code>
<code>id | id_filial | id_department | id_position | full_name | email_user | id_number | tel_number
</code>
id | id_filial | id_department | id_position | full_name | email_user | id_number | tel_number
filial_work :
<code>id | filial
</code>
<code>id | filial
</code>
id | filial
department_work :
<code>id | department | department_email
</code>
<code>id | department | department_email
</code>
id | department | department_email
position
<code>id | position
</code>
<code>id | position
</code>
id | position
number_work :
<code>id | number
</code>
<code>id | number
</code>
id | number
I need the data output to be like this :
And I get this one :
Here is my output code to the page:
<code><tbody>
<?php foreach($postsContact as $key => $contacts): ?>
<tr class="phonebook-row unit" data-unit-id="1" data-units="[]">
<td colspan="7" class="unit-header">
<span class="unit-name"><?=$contacts['filial']?></span>
</td>
</tr>
<tr class="phonebook-row unit" data-unit-id="1" data-units="[]">
<td colspan="7" class="unit-header">
<span class="unit-name"><?=$contacts['department']?></span>
</td>
</tr>
<tr data-units="[1]" data-person-id="1" class="phonebook-row person">
<td style="width: 200px;"><?=$contacts['position'];?></td>
<td><?=$contacts['full_name'];?></td>
<td><?=$contacts['email_user'];?></td>
<td><?=$contacts['number'];?></td>
<td><?=$contacts['tel_number'];?></td>
<td><a href="workers/edit.php?id=<?=$contacts['id'];?>">edit</a></td>
<td><a href="workers/edit.php?delite_id=<?=$contacts['id'];?>">delete</a></td>
</tr>
<?php endforeach; ?>
</tbody>
</code>
<code><tbody>
<?php foreach($postsContact as $key => $contacts): ?>
<tr class="phonebook-row unit" data-unit-id="1" data-units="[]">
<td colspan="7" class="unit-header">
<span class="unit-name"><?=$contacts['filial']?></span>
</td>
</tr>
<tr class="phonebook-row unit" data-unit-id="1" data-units="[]">
<td colspan="7" class="unit-header">
<span class="unit-name"><?=$contacts['department']?></span>
</td>
</tr>
<tr data-units="[1]" data-person-id="1" class="phonebook-row person">
<td style="width: 200px;"><?=$contacts['position'];?></td>
<td><?=$contacts['full_name'];?></td>
<td><?=$contacts['email_user'];?></td>
<td><?=$contacts['number'];?></td>
<td><?=$contacts['tel_number'];?></td>
<td><a href="workers/edit.php?id=<?=$contacts['id'];?>">edit</a></td>
<td><a href="workers/edit.php?delite_id=<?=$contacts['id'];?>">delete</a></td>
</tr>
<?php endforeach; ?>
</tbody>
</code>
<tbody>
<?php foreach($postsContact as $key => $contacts): ?>
<tr class="phonebook-row unit" data-unit-id="1" data-units="[]">
<td colspan="7" class="unit-header">
<span class="unit-name"><?=$contacts['filial']?></span>
</td>
</tr>
<tr class="phonebook-row unit" data-unit-id="1" data-units="[]">
<td colspan="7" class="unit-header">
<span class="unit-name"><?=$contacts['department']?></span>
</td>
</tr>
<tr data-units="[1]" data-person-id="1" class="phonebook-row person">
<td style="width: 200px;"><?=$contacts['position'];?></td>
<td><?=$contacts['full_name'];?></td>
<td><?=$contacts['email_user'];?></td>
<td><?=$contacts['number'];?></td>
<td><?=$contacts['tel_number'];?></td>
<td><a href="workers/edit.php?id=<?=$contacts['id'];?>">edit</a></td>
<td><a href="workers/edit.php?delite_id=<?=$contacts['id'];?>">delete</a></td>
</tr>
<?php endforeach; ?>
</tbody>
The output function :
<code>function selectAllFromContact ($table1 , $table2 , $table3 , $table4 , $table5){
global $pdo;
$sql = "SELECT
t1.id,
t1.full_name,
t1.email_user,
t1.tel_number,
t2.filial,
t3.department,
t4.position,
t5.number
FROM $table1 AS t1 INNER JOIN $table2 AS t2 ON t1. id_filial = t2.id
INNER JOIN $table3 AS t3 ON t1. id_department = t3.id
INNER JOIN $table4 AS t4 ON t1. id_position = t4.id
INNER JOIN $table5 AS t5 ON t1. id_number = t5.id";
$query = $pdo->prepare($sql);
$query->execute();
dbCheckError($query);
return $query->fetchAll();
</code>
<code>function selectAllFromContact ($table1 , $table2 , $table3 , $table4 , $table5){
global $pdo;
$sql = "SELECT
t1.id,
t1.full_name,
t1.email_user,
t1.tel_number,
t2.filial,
t3.department,
t4.position,
t5.number
FROM $table1 AS t1 INNER JOIN $table2 AS t2 ON t1. id_filial = t2.id
INNER JOIN $table3 AS t3 ON t1. id_department = t3.id
INNER JOIN $table4 AS t4 ON t1. id_position = t4.id
INNER JOIN $table5 AS t5 ON t1. id_number = t5.id";
$query = $pdo->prepare($sql);
$query->execute();
dbCheckError($query);
return $query->fetchAll();
</code>
function selectAllFromContact ($table1 , $table2 , $table3 , $table4 , $table5){
global $pdo;
$sql = "SELECT
t1.id,
t1.full_name,
t1.email_user,
t1.tel_number,
t2.filial,
t3.department,
t4.position,
t5.number
FROM $table1 AS t1 INNER JOIN $table2 AS t2 ON t1. id_filial = t2.id
INNER JOIN $table3 AS t3 ON t1. id_department = t3.id
INNER JOIN $table4 AS t4 ON t1. id_position = t4.id
INNER JOIN $table5 AS t5 ON t1. id_number = t5.id";
$query = $pdo->prepare($sql);
$query->execute();
dbCheckError($query);
return $query->fetchAll();
I will be very grateful for your help
I tried to find the answer on the Internet, but I couldn’t