title: Count the number of rows in MySQL table with criteria depending on other table
body: <p>I've got two tables:</p>
  
  <pre><code>content:
  id    access
  1     3
  2     5
  3     9
  
  viewlevels:
  id   group
  1    [10,12,15]
  2    [8,12,11]
  3    [9,10,5]
  </code></pre>
  
  <p>The access field in content is related with the id field in viewlevels.</p>
  
  <p>I select the rows in viewlevels depending on the current user group. So for example, if group is = 10, my query will select rows 1 and 3. If the group is 12, it will select rows 1 and 2, etc. I'm using the following query:</p>
  
  <pre><code>$query="SELECT id FROM #__viewlevels WHERE rules LIKE '%$group%'";
  </code></pre>
  
  <p>My challenge is to count the number of rows for column id in table content where the access matches with the selected id's from the above query on table viewlevels.</p>
  
  <p>I tried the following code but it is returning the error: undefined variable: nartigos</p>
  
  <pre><code>$query="SELECT count(id) FROM #__content WHERE access IN (SELECT id FROM #__viewlevels WHERE rules LIKE '%$group%')";
  
  if ($stmt = mysqli_prepare($link, $query)) {
  
      /* execute query */
      mysqli_stmt_execute($stmt);
  
      /* store result */
      mysqli_stmt_store_result($stmt);
  
      $nartigos=mysqli_stmt_num_rows($stmt);
  
      /* close statement */
      mysqli_stmt_close($stmt);
  };
  
  echo "Nº de artigos " .$nartigos;
  </code></pre>