title: Fetching values from mySQL into a multi-dimensional array
body: <p>I have an array of 'search tags' submitted by my users, such as <em>apples, oranges, anger, love etc</em>. Each set of these tags are put into an array. The array represents a set of tags submitted by a unique user. </p>
  
  <p>I want to take these tags, submit them into the database, and fetch the corresponding books in the same row as these tags. The books must be in the same kind of array structure as the tags so that they can be assigned back to each user in the html script. </p>
  
  <p>Example: <code>tagsarray[0][1] = 'love'</code> ,  <code>booksarray[0][1] = 'the book corresponding to 'love''</code></p>
  
  <p>I had an idea of how I could make this work, using loops and push arrays. I wrote this script below, <em>but it simply isn't working.</em> </p>
  
  <pre><code>&lt;?php
  
  
  $tags = array(array("apples","oranges", "pears"), 
                array("sun", "blood"), 
                array("anger", "love"));
  
  $con = mysql_connect("Stories.mysql.anyhost.com", "user", "password");
  
  mysql_select_db("Stories");
  
  foreach ($tags as $tag) {
  
      $one = array();
      $two = array();
  
      for ($i = 0; $i &lt; count($tag); $i++) {
  
          $tag_value = $tag[$i];
          $selectbooks = "SELECT * FROM Journeys 
                          WHERE book_tags = '$tag_value'";
  
          $query = mysql_query($selectbooks);
  
          while ($row = mysql_fetch_assoc($query)) {
              $one[] = $row['books'];
          }
  
          $two[] = $one;
  
      }
  }
  
  echo json_encode($two); 
  // should echo out [ [books1, books2], [books3, books4], [books5, books6] ] - but instead it returns [[]] 
  
  mysql_close($con);
  ?&gt;
  </code></pre>
  
  <p>It would be great if someone could pinpoint the fault with my script and/or suggest a better alternative.</p>