0

Ive got a database that Im trying to pull data from (the name of each unique identifier and also how many times it appears in the database) by using this query:

$query = "SELECT Dcol, COUNT(*) FROM dtest GROUP BY Dcol";

and then using this to actually print the data out:

while($result->fetch_row()){

$row = $result->fetch_array(MYSQLI_NUM);
printf("<strong>%s</strong> : <i>%s</i><br />",$row[0],$row[1]);

}

and it works great except for the fact that it only gets 2 of the 4 unique items from the Dcol column. I've tested it by just putting everything that the fetch_row() returns into an array and then using print_r and when I do that it actually shows all 4 with the correct number of times it was used, but when I try to print it using the above statement I get 2 of the 4 (the second and fourth one, if that helps at all)

Can anyone tell me why this would only be giving two of the four unique items?

1 Answer 1

1

The 'fetch_row' command is getting the first row - then you ask for the 2nd row with the 'fetch_array' command. So you're only seeing 2 and 4 as a result.

Sign up to request clarification or add additional context in comments.

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.