I already asked this but I dont know how to fix it please help, my $obj->obtainID($a); i returns nothing for the second index.
Description:
I got an $arrayDirectoy variable which contains just 2 values, then I tried to pass that variable to a query in a for loop to retrieve the ids of each one, but It just echo me one id, and there are two ids, I dont know how to fix that, It just print me 1 id.
Example $arrayDirectory[] = {user1, user2};
it must echo 1 2 but just print me 1
for($i=0;$i<sizeof($arrayDirectory);$i++){
$res[$i] = $obj->obtainID($arrayDirectory[$i]);
echo $res[$i];
}
this is my obtainID method
public function obtainID($user){
$conexion = $this->objConexion->configuracion();
$query = "CALL sp_xxx('$user')";
$stmt = $conexion->prepare($query);
$stmt->execute();
$resultado = $stmt->fetchColumn();
return $res;
}
There are a couple issues. First, you have a syntax error — you forgot a closing parenthesis to sizeof():
Also, if you’re not changing the number of elements, there’s no need to call
sizeof()more than once:Lastly, you should be calling
count()orsizeof()on$arrayDirectory[0], not$arrayDirectory. This is because the array only has one element, which happens to be an object that contains two fields. Alternatively, it probably makes sense for$arrayDirectoryto just be an object, not an array.So, your final code should look like: