How to merge several columns into one and remove duplicate mysql? Here is an example code:
$result = mysql_query ("SELECT CONCAT(channeltv,',',channeltv2,',',channeltv3,',',channeltv4) as output FROM igry"); while ( $itemm = @mysql_fetch_array( $result ) ) : echo $itemm['output']; endwhile; As a result, I get something like this: channel1, channel3, channel10, channel12 channel1 ,,, channel5, channel1, channel10, etc ...
Ie all in one line, a comma is displayed if the cell is empty and doubles are displayed.
And what was needed was this:
channel1
channel3
channel5
channel10
channel12
etc...
How to write such code?
select channeltv from igry UNION select channeltv2 from igry ...In general, we must look towards changing the structure of the database. storing several values of the same nature in one column is not accepted - Mike