title: MySQL Loading Rows via String's Contents
body: <p>I'm making a "Like" button for a portfolio website I'm working on and I've gotten stumped by some of my own code!</p>
  
  <p>I have two MySQL tables:</p>
  
  <ul>
  <li><strong>img_all</strong>: contains all images on the server (each image has a 6 <em>INT</em> id)</li>
  <li><strong>login</strong>: contains account information for all users of the website (each user has a 6 <em>INT</em> id as well a <em>VARCHAR</em> column labeled "likes")</li>
  </ul>
  
  <p>The way my system is laid out. When a user "Likes" a picture, I save that picture's id to a column on the login table.</p>
  
  <pre><code>UPDATE login SET likes = CONCAT(likes,':$img_id:') WHERE user_key = $user_id;
  </code></pre>
  
  <p>and when they unlike a picture:</p>
  
  <pre><code>UPDATE login SET likes = REPLACE(likes,':$img_id:','') WHERE user_key = $user_id;
  </code></pre>
  
  <p>This will output strings in the <em>likes</em> column similar to this:</p>
  
  <pre><code>:456093:475829:203944:789203:
  </code></pre>
  
  <p>My problem starts here. I'm making a page that allows users to view all the pictures that they've liked (let's call this file "Likes.php").
  However, the list of liked pictures are saved in the <em>login</em> table, while the actual picture information is saved in <em>img_all</em>.</p>
  
  <p>How then do I take the list from my <em>login</em> table and translate it to select those images from <em>img_all</em>? I was thinking of using a mixture of:</p>
  
  <pre><code>SELECT user_key FROM login WHERE likes LIKE '%:$img_id:%';
  </code></pre>
  
  <p>and</p>
  
  <pre><code>while();
  </code></pre>
  
  <p>I also thought of a SQL query. I know it won't work. However, hopefully, it will also help relay what I'm trying to accomplish!</p>
  
  <pre><code>SELECT * FROM
  img_all WHERE id =
        SELECT likes FROM login
              WHERE likes LIKE '%:$img_id:%' AND user_key = '$user_id';
  </code></pre>