Special Muesli Special Muesli - 1 year ago 67
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);

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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download