user1365010
user1365010

Reputation: 3363

Really basic query working in PMA but not in PHP

This is the query

$db=mysql_connect('localhost','root','root');
mysql_select_db('test');
$query=mysql_query("SELECT * FROM table");
$r=mysql_fetch_assoc($query);
print_r($r);

It only gives me the first element.

But in PhpMyAdmin it gives me all the elements.

How can I make it work in PHP?

Upvotes: 0

Views: 60

Answers (1)

TwiN
TwiN

Reputation: 1911

mysql_fetch_assoc fetches one row per function call. What you want is probably:

while($r = mysql_fetch_assoc($query)){
    print_r($r);
}

Upvotes: 2

Related Questions