I need to retrieve data from 2 tables. My SQL shown below works perfectly. The problem is that I made a foreach
to retrieve the data from the second table by the ID
field that is conflicting with the first table since both have the ID
field.
SQL
$sql = "SELECT tb_faqs.*, tb_paginas.*
FROM (tb_faqs INNER JOIN tb_paginas)
WHERE tb_faqs.ID = '$id'
AND tb_faqs.id_pagina = tb_paginas.ID";
$query = $pdo->query($sql);
$pagina = $query->fetch();
This SQL query fetches all data needed for both tables but I need to foreach
in the second table to mount a dynamic% . This is select
:
foreach ($pdo->query($sql) as $pagina) {
echo '<option value="'.$pagina['ID'].'" '.(($pagina['id_pagina'] == $pagina['ID']) ? 'selected="selected"' : "").'>'.$pagina['pagina'].'</option>';
}
Question: When two tables have the same column name , how to specify in which table that column?