Save the total of rows from a SELECT with WHERE in a variable

0

I need to develop a code where the row total of a SELECT is stored in a variable. I wrote the code below, but when I use WHERE it returns a "Notice: Trying to get property of non-object in" error.

Is it possible to do a SELECT using a WHERE and save the total of records located in a variable with the format "0000"?

include "conecta_mysql.inc";

$escritorio = $_POST["n_escritorio"];

$resultado = $mysqli->query("SELECT * FROM registros WHERE escritorio=$escritorio");
$linhas = $resultado->num_rows;

$mysqli->close();
    
asked by anonymous 04.02.2018 / 06:02

1 answer

0

Thank you all for the help. One person helped me with the following solution:

$escritorio = $_POST["n_escritorio"];

echo "$escritorio<br>";

$resultado = $mysqli->prepare("SELECT * FROM registros WHERE escritorio = '".utf8_decode($escritorio)."'");
$resultado->execute();
$resultado->store_result();

$linhas = $resultado->num_rows;
echo "total: $linhas";

$mysqli->close();
    
06.02.2018 / 03:42