Pardon my programming differences, but below is how I might write it.
Looking at your code, it looks like you want to sort by the genres in your genre list and list each set of items in multiple rows. Also, it looks like genrelist is a single row that has comma delimited values. I'm doing some guessing as to your table structures, so you will need to interpret my code to better fit your scenario.
Using mysql_fetch_array($result,MYSQL_ASSOC) sets each item in the row to a variable name equal to their column name in their database table. Example, if the column name was ID_Number, the item in that column would be set to variable $ID_Number.
Connect_To_DB() is a function I write to connect to my MySQL server and make my database connection for me. It returns the connection as a variable.
I left out the coloring information, as I'm not sure under what circumstances you want to apply it.
$num_columns="2";
$q="select genreslist from Members where MemberID ='$_SESSION[MemberID]' ";
$connection=Connect_To_DB();
$result=mysql_query($q)
or die("Select from Members table had errors - ".mysql_error());
mysql_close($connection);
if($row=mysql_fetch_array($result,MYSQL_ASSOC))
{
extract($row);
$genre_array=explode(",",$genrelist);
}
else $genre_array=array();
echo "<table border='0' width='100%' cellspacing='0' cellpadding='0' align=center>";
foreach($genre_array as $genre_item)
{
$q1="select * from genres where genre=\"$genre_item\" ";
$connection=Connect_To_DB();
$result=mysql_query($q1)
or die("Select from genres table had errors - ".mysql_error());
mysql_close($connection);
echo "<tr><td><font color=\"red\">$genre_item</font></td></tr>";
$counter=1;
while($row=mysql_fetch_array($result,MYSQL_ASSOC))
{
extract($row);
if ($counter%$num_columns==1) echo "<tr>\r\n<td>";
else echo "<td>";
echo "$id";
if ($counter%$num_columns==0) echo "</td>\r\n<\tr>";
else echo "</td>";
$counter++;
}
if ($counter%$num_columns!=0) echo "</tr>";
}
echo "</table>";
You will note I set the variable $num_columns, so you can decide how many columns you want. I hope this code gives you some ideas of how you might want to organize your data.
Good Luck!