Jump to content

Recommended Posts

Hi,

 

I have the following query to detect dupes:

SELECT tablename.*, COUNT(*) FROM tablename GROUP BY fieldname HAVING COUNT(*) > 1

 

and I would like to display COUNT(*) via echo in the results output, how do I accomplish this?

I've tried echo "$row[COUNT(*)]"; with no success.

 

I am basically wanting to display the number of times each field is duplicated.  I notice if I use phpmyadmin and run the query it displays a COUNT(*) field that details the repetitions and would like to do the same via my php.

Link to comment
https://forums.phpfreaks.com/topic/208557-display-count/
Share on other sites

COUNT(*) is generally not a good idea. It is better to put the id field name in there. This will make the query more efficient.

 

To be able to pull the data you want to alias the column:

 

SELECT tablename.val1, tablename.val2, COUNT(id) as id_cnt FROM ...

 

Then you would reference it by $results['id_cnt']

Link to comment
https://forums.phpfreaks.com/topic/208557-display-count/#findComment-1089661
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.