Reputation: 515
I know this is basic, but I can't seem to find the answer:
I have a query that returns the desired rows in PHPMyAdmin but am clearly doing something wrong on my page because it only seems two return rows in the array.
Here is the code:
$editgroupid = 'm101';
$query = "SELECT dentists.id
from groups, groupdentlink, dentists
WHERE groups.id = '$editgroupid'
AND groups.id = groupdentlink.f_group_id
AND groupdentlink.f_dent_id = dentists.id
ORDER BY dentists.name";
$resultdent = mysql_query($query) or die(mysql_error());
$dents = mysql_fetch_array($resultdent);
print_r(array_values($dents));
On the page I get:
Array ( [0] => UTG69 [1] => UTG69 )
But in PHPMyAdmin I get like 40 rows.
Upvotes: 1
Views: 95
Reputation: 214
You are usingmysql_fetch_array() function which as you can see in documentation (http://php.net/manual/en/function.mysql-fetch-array.php) loads only one row retrieved from query. At given site you have example how to manage multiple rows.
Upvotes: 0
Reputation: 53359
mysql_fetch_array only returns one row at a time. To get all the rows, generally you loop through, calling mysql_fetch_array each time.
while ($row = mysql_fetch_array($resultdent)) {
// Here you have access to the current $row
var_dump($row);
}
Upvotes: 3