foreign key problems when selecting items

Asked

Viewed 25 times

0

Well, I’m trying to select all items from two separate listings, but without success, I’m using:

Query

select t*, d.id as id_discvinculada from textos as t join disciplinas as d on t.id_discvinculada = d.id

Function

function listagemTextos($conexao){
    $textos = array();
    $resultado = mysqli_query($conexao, "select t*, d.nome_disciplina as id_discvinculada from textos as t join disciplinas as d on t.id_discvinculada = d.id");
    while($texto = mysqli_fetch_assoc($resultado)){
        array_push($textos, $texto);
    }
    return $textos;
}

Function call

<?php

$textos = listagemTextos($conexao);

foreach ($textos as $texto){
    ?>

    <div>
        <div>
            <h4><?= $texto["titulo"] ?></h4>
            <label><?= $texto["id_discvinculada"] ?></label>
            <ul>
                <span>Opções</span>
                <li>Alterar</li>
                <li><a href="logicas/logica-remover_texto.php?id=<?= $texto['id']?>">Remove</a></li>
            </ul>
        </div>
        <div>
            <?= $texto["texto"] ?>
        </div>
    </div>

    <?php
}

Disciplines

Disciplinas

Texts

Textos Table

Warning

Warning
: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in
C:\xampp\htdocs\dev_port\historia\logicas\banco_textos.php
on line
7

As I add Foreign Key, and use it so I can display the items correctly in the function call ?

  • 1

    Apparently missed a point in your consultation on t*, right at the start. You can check the error using the function mysqli_error.

1 answer

2


Tries to change his query for that reason:

select t.*, d.nome_disciplina as id_discvinculada from textos t
join disciplinas d on t.id_discvinculada = d.id

Browser other questions tagged

You are not signed in. Login or sign up in order to post.