0

I want to select data from joined tables.

I'm getting an error Warning:

mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given

This is the code:

<?php

$consulta = mysqli_query($conexao, "SELECT exercicios.nome_exercicio AS  nome_exc , exercicios.repeticoes_exercicio  AS rep_exc , exercicios.serie  AS serie_exc FROM exercicios 
    INNER JOIN usuarios ON usuarios.id_usuario = exercicios.id_usuario
    WHERE id_usuario  = usuarios.id_usuario
");

if (mysqli_num_rows($consulta) > 0) {
    while ($exercicio = mysqli_fetch_assoc($consulta)) {
        echo "<div class='table-responsive'><table class='table table-responsive'>

<tr><td></td><td>Nome</td><td>Repetições</td><td>Série</td></tr>

<td>'".$exercicio['nome_exc']."'</td>
<td>'".$exercicio['rep_exc']."'</td>
<td>'".$exercicio['serie_exc']."'</td>


</table></div> ";
    }
} else {
    echo "Seu instrutor ainda não cadastrou exercícios";
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
VitorTech
  • 23
  • 1
  • 1
  • 9
  • two things:- connection code is missed. and show us the output of `var_dump($consulta);` put it just after query and check. also add `error_reporting(E_ALL);ini_set('display_errors',1);` just after ` – Alive to die - Anant Apr 20 '16 at 05:00
  • can you please run the query in mysql and check for error, is that where condition correct ? please confirm it – krishnakumar kk Apr 20 '16 at 05:02

2 Answers2

0

mysqli_query return mysqli_result on success but boolean false on failure (doc), that means your query is failed and returning boolean false. Check your query statement and MySQL table.

Try this SQL:

SELECT exercicios.nome_exercicio AS nome_exc,
   exercicios.repeticoes_exercicio AS rep_exc,
   exercicios.serie AS serie_exc 
FROM exercicios
INNER JOIN usuarios ON usuarios.id_usuario = exercicios.id_usuario
Meathanjay
  • 2,023
  • 1
  • 18
  • 24
0

Seems Like you have problem in your query .

Valid Query is -:

SELECT exercicios.nome_exercicio AS nome_exc,
   exercicios.repeticoes_exercicio AS rep_exc,
   exercicios.serie AS serie_exc 
FROM exercicios
INNER JOIN usuarios ON usuarios.id_usuario = exercicios.id_usuario
Md Mahfuzur Rahman
  • 2,319
  • 2
  • 18
  • 28