Xevrrer
Xevrrer

Reputation: 35

PHP (and SQL) how to get given record

I have Data base "players" with:

id Name gold
1 joe 50
2 tom 40
3 jzd 70

I use a PHP to get info from base to variable:

$base = $connection->query("SELECT * FROM Players");
$data = $base->fetch_assoc();

When i use

$data['name'];

I get only a name FIRST id, how to get name for example id 2 or 3?

Upvotes: 0

Views: 29

Answers (1)

Steve
Steve

Reputation: 1943

If you want to return the record for a specific user use

SELECT * FROM players WHERE id = <id>;

If you want to list all the players returned from your first query (select all, no where statement), you need to loop through the array returned from doing your query. Use a foreach (here are some examples

Upvotes: 1

Related Questions