Special Muesli Special Muesli - 3 months ago 10
PHP Question

Mysqli, SELECT FROM, php

I'm trying to do a simple SELECT username FROM users from a database

$sql = "SELECT username
FROM users";

$select_sql = mysqli_query($conn, $sql);
$parse_sql = mysqli_fetch_array($select_sql);
var_dump($parse_sql);


but it gives me this with var_dump while having multiple entries.


array(2) { [0]=> string(0) "" ["username"]=> string(0) "" }


Other queries like this are working fine

$sql = "SELECT username, password FROM users WHERE username ='$user'";
$select_sql = mysqli_query($conn, $sql);


I can't find what's wrong

Answer

Use while loop to get all the users in db_user

$sql = "SELECT username
FROM db_user";

$select_sql = mysqli_query($conn, $sql);
while($parse_sql = mysqli_fetch_assoc($select_sql))
{
  $usernames[] = $parse_sql
}

var_dump($usernames);
Comments