Error in SQL code subconsultation

Asked

Viewed 31 times

0

My mistake is this

Warning: mysql_fetch_array() expects Parameter 1 to be Resource, Boolean Given in C: xampp htdocs BD project proj_details.php on line 25

<?php
$base_dados = "crowdfunding";
$conexao = mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db($base_dados) or die(mysql_error());
$sql = "SELECT projeto.id, nome, limite, projeto.descricao FROM projeto,(SELECT valor, recompensa.descricao FROM recompensa, projeto WHERE projeto.id = id_projeto)";
$resultado = mysql_query($sql);
?>

<html>
<head>
<title>Projetos Atuais</title>
</head>
<body>
    <h1>Detalhes de um Projeto<br /></h1>
    <table>
    <tr>
    <td><strong>ID</strong></td>
    <td><strong>Nome</strong></td>
    <td><strong>Data Final</strong></td>
    <td><strong>Descricao</strong></td>
    <td><strong>Valor da Recompensa</strong></td>
    <td><strong>Descricao da Recompensa</strong></td>
    </tr>
    <?php
    while($dados = mysql_fetch_array($resultado)){
    $id = $dados['id'];
    $nome = $dados['nome'];
    $data = $dados['limite'];
    $descricao_proj = $dados['projeto.descricao'];
    $valor = $dados['valor'];
    $descricao_rec = $dados['recompensa.descricao'];

    echo "<tr>
        <td>$id</td>
            <td>$nome</td>
            <td>$data</td>
            <td>$descricao_proj</td>
        <td>$valor</td>
        <td>$descricao_rec</td>  
    </tr>";
}
?>
</table><br /><br />
<form action="menu1.php" method="get">
    <center><input name="botao" type="submit" value="Voltar"/></center>
</form>
</body>
</html>
  • The error is clear, the function mysql_fetch_array() expecting a resource and is receiving a Boolean. Probably your query is returning false.

  • Why don’t you use inner join to do this query there, ta very strange.

  • I took the liberty of re-doing this query for you: SELECT project.id, project.name, project.limit, project.Description, reward.value, reward.Description FROM project INNER JOIN reward ON reward.id_project = project.id

  • Bruh, change your duties mysql_ for their duties mysqli_, for support reasons. starting with PHP 5.5+ these functions are deprecated and no longer exist in PHP 7

No answers

Browser other questions tagged

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