title: Making a tag cloud with MySQL and PHP
body: <p>I'm making a tag cloud. I have a table called tags with a row 'id' and row 'tag'. </p>
  
  <p>Each row 'tag' will be a tag just like on this site - imagine a tag called 'foo' for this example.</p>
  
  <p>Each row 'id' will be the id's of the webpages that are tagged something - 'foo', in this example.</p>
  
  <p>So any arbitary row may look like:</p>
  
  <pre><code>foo | 3 6 16 39 43 58 38 12 55
  </code></pre>
  
  <p>How do I make a function that will check the entire table for existence of $tag, and if it exists - add a space and $id to the row 'id' for that tag. If the tag doesn't exist in my table, then add the tag, and add the id.</p>
  
  <p>The code I have (half-PHP, half-pseudo) is as follows:</p>
  
  <pre><code>if($tag doesnt exist in table)
  {
       mysql_query("INSERT INTO tags (tag, id) VALUES ('$tag', '$id'");
  }
  if($tag exists in table)
  {
       mysql_query("...append somehow... $id . " " WHERE tag = '$tag'");
  }
  </code></pre>
  
  <p>I just don't know what to put in the conditionals or how to append in SQL how I want. How can I do this?</p>