I am pulling a list of genres from a database and I am trying to sort them by the most common occurrences. But when I pull them from the database, they are still separated:
Array
(
[0] => Blues Rock
[1] => Garage Rock
[2] => Hard Rock
)
Array
(
[0] => Garage Rock
[1] => Blues Rock
[2] => Hard Rock
)
But I want it to come out into one array that can be sorted to pull the top genres. It should look like Genres: Garage Rock, Blues Rock, Hard Rock
Here's my code:
$genreSql = "SELECT `genres` FROM `song_genres` WHERE `album_id` = '$album_id' AND `band_id` = '$band_id'";
$queryGenre = mysqli_query($conn, $genreSql) or die (mysqli_error($conn));
while ($rowG = mysqli_fetch_array($queryGenre)){
$genres = $rowG['genres']; // Goes into the db as a string. E.g. "Str1, Str2, Str3"
$genres = explode(", ", $genres);
echo "<pre>";
print_r($genres);
echo "</pre>";
I haven' gotten any further because I'm just trying to organize it all into one single array.
It might be that I don't know what I'm doing - because I'm still crap when it comes to arrays - but maybe veterans of php will find something.