PHP Database Search

Asked

Viewed 62 times

1

I have a database with 3 tables and I need to know if in table A (for example) the field guy for 0 will fetch data from table B, if for 1 will fetch data from table C.

And I have the following code that was already on the site (when I picked it up), and gives error :

Warning: mysqli_fetch_array() expects Parameter 1 to be mysqli_result, Boolean Given

 <?php
 include("connection.php");
 mysqli_set_charset($con,"utf8");

 <tbody aria-live='polite' aria-relevant='all'>";
  $result3 = mysqli_query($con,"SELECT lugar,dorsal as id,tipo as classe from classificacao where tipo2=70");
  while($row3 = mysqli_fetch_array($result3)){
   if($row3['classe'] == 0){
    $result8 = mysqli_query($con,"SELECT r.nome, r.equipa from registo r where id=r.Dorsal and classe = 0");
    while($row4 = mysqli_fetch_array($result8)){
        echo "<tr>";
        echo "<td>" . $row3['lugar'] . "</td>";
        echo "<td>" . $row3['id'] . "</td>";
        echo "<td>" . $row4['nome'] . "</td>";
        echo "<td>-</td>";
        echo "<td>" . $row4['equipa'] . "</td>";
        echo "</tr>";
    }
   }
   else{
    $result9 = mysqli_query($con,"SELECT f.nome, f.n_federado, f.equipa from registofederados f where id=f.Dorsal and classe = 1");
    while($row5 = mysqli_fetch_array($result9)){//linha 345
         echo "<tr>";
         echo "<td>" . $row3['lugar'] . "</td>"; 
         echo "<td>" . $row3['id'] . "</td>";
         echo "<td>" . $row5['nome'] . "</td>";
         echo "<td>" . $row5['n_federado'] . "</td>";
         echo "<td>" . $row5['equipa'] . "</td>";
        echo "</tr>";
    }
  }
 }
 echo "</tbody>
</table>
</div>";
mysqli_close($con);
?>
  • <tbody aria-live='polite' aria-relevant='all'>"; Your code has syntax error. Do not mix PHP with HTML.

  • That code is a mess...

  • @Jorgeb. But that’s how I took it..

  • @Brunogibellino what is happening is that the research is not returning anything.

  • You have data on the table registofederados?

  • @Jorgeb. Yes I have only one datum

  • with classe = 1 ?

  • @Jorgeb. Yes all that is federated is class 1

  • but you have some record with classe = 1 at the bank?

  • In all mysqli_query() before the point and comma, add, die(mysqli_error($con));

Show 5 more comments

1 answer

1


Note that you in your SQL query was wrong and were writing HTML inside PHP! Try it this way:

 <?php
 include("connection.php");
 mysqli_set_charset($con,"utf8");
 ?>
 <tbody aria-live='polite' aria-relevant='all'>;
 <?php
  $result3 = mysqli_query($con,"SELECT lugar,dorsal,tipo as classe from classificacao where tipo2=70");
  while($row3 = mysqli_fetch_array($result3)){
      $dorsal = $row3["dorsal"];
   if($row3['classe'] == 0){
$result8 = mysqli_query($con,"SELECT r.nome, r.equipa from registo r   where id=" . $dorsal . " and classe = 0");
while($row4 = mysqli_fetch_array($result8)){
    echo "<tr>";
    echo "<td>" . $row3['lugar'] . "</td>";
    echo "<td>" . $row3['id'] . "</td>";
    echo "<td>" . $row4['nome'] . "</td>";
    echo "<td>-</td>";
    echo "<td>" . $row4['equipa'] . "</td>";
    echo "</tr>";
}
   }
   else{
    $result9 = mysqli_query($con,"SELECT f.nome, f.n_federado, f.equipa from registofederados f where id=" . $dorsal . " and classe = 1");
while($row5 = mysqli_fetch_array($result9)){
     echo "<tr>";
     echo "<td>" . $row3['lugar'] . "</td>"; 
     echo "<td>" . $row3['id'] . "</td>";
     echo "<td>" . $row5['nome'] . "</td>";
     echo "<td>" . $row5['n_federado'] . "</td>";
     echo "<td>" . $row5['equipa'] . "</td>";
    echo "</tr>";
}
  }
 }
?>
</tbody>
</table>
</div>
<?php
mysqli_close($con);
?>
  • Continues to give error Warning: mysqli_fetch_array() expects Parameter 1 to be mysqli_result, Boolean Given in C: xampp htdocs exercicios Oxygentarget php verregistosA.php on line 345

  • what mistake you’re making this time?

  • The line 345 in this code snippet is the line...

  • I already added a comment to the code indicating the error line

  • Try Now sff

  • It keeps giving the same error. I’m new to php and sql, and even php itself. Can you tell me what that error is?

  • what I know is the query that is returning a false..

  • tried using mysql_fetch_array()?

  • Try the following solution: http://pastebin.com/VScUCt8Z - I pointed out some errors as well, as an observation.

Show 4 more comments

Browser other questions tagged

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