Skip to content
Advertisement

count multiple values in multiple column PHP

i want to count multiple values from 3 columns and sorted descending using PHP mysqli, and I can’t do it.

name1 name2 name3
mike jack rose
jack mike Mary
jack Mary John

expect output:

JavaScript

My code:

JavaScript

Advertisement

Answer

Use UNION to get them all into a single column. Then use COUNT(*) and GROUP BY:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement