Save total lines of a SELECT with WHERE in a variable

Asked

Viewed 52 times

0

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

It is possible to make a SELECT using a WHERE and save the total number 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();
  • The returned result is integer. If you want to format the result, check how many houses this number has and complete with zeros left to form 4 digits.

  • Jefferson, good afternoon! In this case I must use a switch case to check the number of digits and complete concatenating with 0?

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();

Browser other questions tagged

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