2

This is my code.

$sqlcount = "SELECT count(*) AS C, Horse_ID FROM images WHERE Horse_ID = 24 GROUP BY Horse_ID HAVING COUNT(*) > 1 LIMIT 0, 30";

//echo $sqlcount;       

$resultcount = $conn->query($sqlcount); 

$rowcount = $result->fetch_assoc();

echo $rowcount['C'];

Why won't it echo the number 4, which is what shows when I test it in phpmyadmin? There are 4 duplicate values in that table hence the 4.

2 Answers 2

2
 $rowcount = $result->fetch_assoc();

to

 $rowcount = $resultcount->fetch_assoc();
Sign up to request clarification or add additional context in comments.

1 Comment

@Charlotte: don't forget to accept this answer. To do so, click the tick mark to the left of the answer, so it turns green. This helps both the poster (they get a few internet points) and other readers (who see which was the preferred answer). Thanks!
0

If you want the number of duplicates in the database, why not write the query to get that value?

SELECT COUNT(*)
FROM (SELECT count(*) AS C, Horse_ID
      FROM images
      WHERE Horse_ID = 24
      GROUP BY Horse_ID
      HAVING COUNT(*) > 1 
     ) i;

Then, you will only be returning one value from the database to the application (which is faster) and there is no need to artificially limit the count to 30.

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.