1

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.

2
  • not all of your code was in a code block, i fixed that Commented Sep 21, 2011 at 1:27
  • Are you running the output of $query in PHPMyAdmin or typing what you think the query is? Commented Sep 21, 2011 at 1:30

2 Answers 2

3

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);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the help. Currently Googling 'put mysql result into array'.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.