Aurange
Aurange

Reputation: 963

MySQL Select All Data From One Column

I want to select all of the usernames. I tried to do SELECT username FROM members and then mysql_fetch_array. So I would do $data["username"]. But I also want to select each row individually. Any help on how to do this would be helpful thank you.

Upvotes: 2

Views: 12221

Answers (3)

John Woo
John Woo

Reputation: 263703

Use PDO for that.Example of using PDO

<?php
$stmt = $dbh->prepare("SELECT username FROM members");
if ($stmt->execute(array($_GET['username']))) {
  while ($row = $stmt->fetch()) {
    print_r($row);
  }
}
?>

Upvotes: 4

TMan
TMan

Reputation: 1905

while($row = mysql_fetch_array($result))
  {
  echo $row['username'];
  }

Upvotes: 1

Rene Pot
Rene Pot

Reputation: 24815

Loop through all results with while()

$result = mysql_query('SELECT username FROM members');

while ($username = mysql_fetch_assoc($result)){
    echo $username['username']; //this will go for every result, so every row in the database
}

Upvotes: 1

Related Questions