0
I’m trying to implement a code to list information from 3 tables. I want to display on the screen only the data that was registered by the user id = '20'
. This value '20' I’m taking from a session variable and I want to put in my product listing function but I’m not getting.
follow:
$idSessao = $_SESSION['sessaoId'];
function listaProdutos($conexao){
$produtos = array();
$resultado = mysqli_query($conexao, "select p.*, c.nome as categoria_nome, u.id as id_usuario from produtos as p inner join categorias as c on c.id = p.categoria_id inner join usuarios as u on u.id = p.usuario_id where p.usuario_id = 20");
while ($produto = mysqli_fetch_assoc($resultado)){
array_push($produtos, $produto);
}
return $produtos;
}
Where is p.usuario_id = 20
would like to do that p.usuario_id = {$idSessao}
but he returns nothing.
Have you checked if you are able to recover the session value correctly? Have you tried printing the SQL code to see if it is correct? Usually doing tests of this kind if you get to the root of the problem.
– mau humor
The value of the variable was not entering the function, so it was blank. But the friend Rodrigo Sartori showed alternatives to take the value and put it within the function
– Edmo Souza