Undefined variable

0

I have a problem, I am following a php programming course and I put the information as it is, the problem is that it throws me an error when I send a variable call.

User function

<?php
function Users(){
    $db = new Conexion();
    $sql = $db->query('SELECT * FROM users');
    if($db->rows($sql) > 0){
            while($d = $db->recorrer($sql)){
                $users[$d['id']] == array(
                    'id' => $d['id'],
                    'user' => $d['user'],
                    'pass' => $d['pass'],
                    'email' => $d['email'],
                    'permisos' => $d['permisos']

                );
            }
    }else{
     $users = false;
    }

    $db->liberar($sql);
    $db->close();
        return $users;     
    }
?>

I call the function from core

$users = Users(); //ERROR!
    
asked by DoubleM 20.01.2018 в 05:33
source

1 answer

1

The problem is that you did not define the variable $ users and the == instead of = in the assignment within the while. Without seeing the Conexion class I would not know if the rest is correct.

<?php
function Users(){
    $db = new Conexion();
    $sql = $db->query('SELECT * FROM users');
    $users = array();
    if($db->rows($sql) > 0){
        while($d = $db->recorrer($sql)){
            $users[$d['id']] = array(
                'id' => $d['id'],
                'user' => $d['user'],
                'pass' => $d['pass'],
                'email' => $d['email'],
                'permisos' => $d['permisos']

            );
        }
    } else {
      $users = false;
    }
    $db->liberar($sql);
    $db->close();
    return $users;     
}
?>
    
answered by 20.01.2018 в 16:41