How do I iterate with an array

0

How do I iterate with a array that I bring from the database in php and then send all those data obtained by a JSON to my view?

This is what I have so far:

$conn = new mysqli($host, $user, $pass, $db);
$errores = array();

if ($conn->connect_error) {
    echo 'false';
}else{
    $razas = $conn->query("SELECT * FROM razas ORDER BY nombre ASC");
    if ($razas->num_rows > 0) {
        $datos = $razas->fetch_assoc();

        $longitud = count($datos);

    }

}

What I want to do is go through the array that brings two fields from the database ... Let's bring everything from the table and pass it by JSON to the view and convert them into <option> tag for a selector .

    
asked by dmedina2150 25.08.2017 в 20:31
source

1 answer

0

You can try doing the following:

if ($razas->num_rows > 0) {
     $datos = $razas->fetch_assoc();
     foreach ($datos as $key => $value) {
        $newarray[$key] = $value;   
    }
}

In this way you can take the values of the arrangement and pass it to another.

    
answered by 25.08.2017 / 20:50
source