I have a problem with PHP and JSON. What I do is try to bring all the data from the database, but it only shows me the first one. If I put a WHERE it brings me the right one but I want everyone and it only brings me the first one. I do not understand what the error may be, I appreciate your help.
$hostname_localhost="localhost";
$database_localhost="drive";
$username_localhost="root";
$password_localhost="";
$json=array();
$conexion = new mysqli($hostname_localhost, $username_localhost, $password_localhost, $database_localhost);
$consulta="SELECT * FROM comercio";
$resultado = mysqli_query($conexion, $consulta);
if($registro=mysqli_fetch_array($resultado)){
$json['comercios'][]=$registro;
}else{
$resultar["comercios"]=0;
}
mysqli_close($conexion);
echo json_encode($json);