title: Joining MySQL tables and comparing columns to list data
body: <p>I have been struggling with the proper way to extract the data I need. I am using MySQL with PHP and will be putting the data into a list format. My only problem is with the actual query itself. Here is how the DB is setup: </p>
  
  <p>I have a 'chars' table for characteristics with the columns 'id', 'descrip', and 'class'. </p>
  
  <p>I have a 'animal' table with the columns 'animal_id', 'charlist', ...</p>
  
  <p>In 'chars' id is an incremented int, 'descrip' and 'class' are text/strings. </p>
  
  <p>'id' and 'descrip' are different for every row but 'class' will be the same sometimes having a value like 'habitat', 'size', 'diet', et cetra. </p>
  
  <p>What I am going for is a list that will look like this: </p>
  
  <ul><strong>Habitat</strong><li>underground</li><li>arctic</li></ul>
  
  <ul><strong>Diet</strong><li>fish</li><li>insects</li><li>omnivore</li></ul>
  
  <p>Here is where I start to have trouble. On a 'Details' page I am showing all of the data specific to a certain animal (whichever is clicked) and to reference the 'characteristics' each animal has it's own 'charlist' value in the database. This value is a string of numbers that reference the 'chars' table, like '2,55,67,90,122'. </p>
  
  <p>So I've pulled all my (specific) animal data to a php variable on the page that I want to supply with the information. Now I need to use the 'charlist' data from that animal to lookup and list the characteristics relative to the animal.</p>
  
  <p>My queries are looking like this, and I know I'm waaay off: </p>
  
  <p>SELECT * FROM 'chars' LEFT INNER JOIN 'animals' ON chars.id IN (animals.charlist) WHERE ...</p>
  
  <p>I've tried a lot of different ways and this is where I get lost. My brain is telling me to join the tables, find the numbers that are in the charlist WHERE animal.animal_id = mysql_real_escape_string($animal_id) - and of course MySQL tells me I can't do it this way. </p>
  
  <p>I know that for the titles of the lists I'll probably have to do this with a GROUP BY condition. </p>
  
  <p>Any help on the query and query syntax would be great. I'm fairly new to MySQL and I'm very happy and eager to learn how to do this right.</p>
  
  <p>Thanks for reading.</p>