Nini Vanini Nini Vanini - 2 months ago 7
SQL Question

Get rows from mysql table to php array

$sql = "SELECT active FROM table_name";
$result = $conn->query($sql);


DB:

|active|
1
1
0
1


I've got table like this and need to get that rows into an array.
Is it possible to get simple array like this?:

$array = (1,1,0,1);


thanks

Answer
$sql = "SELECT active FROM table_name";

$result = $conn->query($sql);

while($row = $result->fetch_assoc()) {
        $arr[]= $row['active'];
    }

print_r($arr);
Comments