MySQL and PHP comparison SUBQUERY

1

I made a query to select all the user records of a table, but I inserted a filter where the admin selects the state and filters only the user records of the selected UF, but is giving return error.

<?php
if( !isset( $_GET['uf'] ) ) {

## Assim funciona corretamente, retorna todos registros de todos usuários
$sql = "SELECT r.* FROM 'registros' FROM 'registros' r WHERE r.'registro' = 'A' ORDER BY r.'registros_data_cad' DESC";

} else if ( isset( $_GET['uf'] ) ) { 

## Assim seleciona apenas registros de um UF, ex: AC
$where_clause = "AND ( SELECT u.'user_uf' FROM 'user' u WHERE u.'user_uf' = '" . mysqli_real_escape_string( $mysqli, $_REQUEST['uf'] ) . "' )";

$sql = "SELECT r.* FROM 'registros' FROM 'registros' r " WHERE r.'registro' = 'A' " . $where_clause . " ORDER BY r.'registros_data_cad' DESC";

}
?>

I tried this way but it gives me a mistake, could you give me a help here?

  

Warning: mysqli_num_rows () expects parameter 1 to be mysqli_result,   boolean given in /home/atc2018/public_html/saldo.php on line 106;

Paste in phpmyadmin gives error # 1054, I consulted and it is non-existent column, however the column exists.

    
asked by anonymous 04.10.2018 / 15:58

1 answer

2

I think the problem is in the "points." of your query .

Try changing your $sql variable as follows:

$sql = "SELECT r.* FROM 'registros' r WHERE r.'registro' = 'A' ". $where_clause ." ORDER BY r.'registros_data_cad' DESC";
    
04.10.2018 / 16:04