0

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/ango/public_html/ficha/findUser.php on line 201

This is the code:

$query = mysql_query("SELECT ango_turnos.planilla.fecha_turno, ango_turnos.planilla.cod_estado, ango_personas.dominio_interno.* FROM ango_turnos.planilla RIGHT OUTER JOIN ango_turnos.reserva ON ango_turnos.reserva.id_turno = ango_turnos.planilla.id_turno LEFT OUTER JOIN ango_turnos.paciente ON ango_turnos.reserva.id_reserva = ango_turnos.paciente.id_reserva LEFT OUTER JOIN ango_personas.dominio_interno ON ango_turnos.paciente.id_persona = ango_personas.dominio_interno.id_persona LEFT OUTER JOIN ango_turnos.horario_medico ON ango_turnos.planilla.id_horario = ango_turnos.horario_medico.id_horario");

if(mysql_num_rows($query)>0){
    while($row = mysql_fetch_array($query)){
        //echo some stuff from $row
    }
}

There is no warning or error involving the connection to the database. This is the only warning I get. SQL query works fine and returns 4 rows in PHPMyAdmin, so I don't know what the problem is.

Gerardo
  • 1,928
  • 4
  • 24
  • 34

2 Answers2

4

You should add an error check after mysql_query() to see what went wrong:

if (!$query) {
    die('Invalid query: ' . mysql_error());
}
John Kugelman
  • 330,190
  • 66
  • 504
  • 555
2

Chances are there has been an error during the execution of your SQL query.

You can check that with msqyl_errno and mysql_error.

(As a side note : outputting the error message is fine while your are on your development machine, but should never be done once your are on a production server : it then should be logged to a file ; so don't forget to put in some configuration option, or stuff like this)

As another side node : the "query" is the SQL string you are giving to mysql_query ; not the result of that function, so your $query variable should have another name, to make the code easier to understand in the future.

Pascal MARTIN
  • 385,748
  • 76
  • 642
  • 654