title: PHP num_returns always returns 1
body: <p><strong>EDIT: Solved</strong></p>
  
  <p>I've found the solution I was looking for. Thanks to Alex for pointing out my mistake. </p>
  
  <p>I was trying to count the number of results from the query that are not empty. </p>
  
  <p>Here's how I did it:</p>
  
  <pre><code>function checkImages($id)
  {
      global $mysqli; 
      $stmt = $mysqli-&gt;prepare("SELECT 
          Img_1,
          Img_2,
          Img_3,
          Img_4,
          Img_5,
          Img_6,
          Img_7,
          Img_8,
          Img_9,
          Img_10,
          Img_11,
          Img_12,
          Img_13,
          Img_14,
          Img_15,
          Img_16,
          Img_17,
          Img_18,
          Img_19,
          Img_20,
          Img_21,
          Img_22,
          Img_23,
          Img_24,
          Img_25,
          Img_26,
          Img_27,
          Img_28,
          Img_29,
          Img_30
          FROM kittens
          WHERE
          id = ?");
      $stmt-&gt;bind_param("i", $id);
      $stmt-&gt;execute();
      $stmt-&gt;bind_result($img1, $img2, $img3, $img4, $img5, $img6, $img7, $img8, $img9, $img10, $img11, $img12, $img13, $img14, $img15, $img16, $img17, $img18, $img19, $img20, $img21, $img22, $img23, $img24, $img25, $img26, $img27, $img28, $img29, $img30);
      while ($stmt-&gt;fetch()){
          $row[] = array('Img_1' =&gt; $img1, 'Img_2' =&gt; $img2, 'Img_3' =&gt; $img3, 'Img_4' =&gt; $img4, 'Img_5' =&gt; $img5, 'Img_6' =&gt; $img6, 'Img_7' =&gt; $img7, 'Img_8' =&gt; $img8, 'Img_9' =&gt; $img9, 'Img_10' =&gt; $img10, 'Img_11' =&gt; $img11, 'Img_12' =&gt; $img12, 'Img_13' =&gt; $img13, 'Img_14' =&gt; $img14, 'Img_15' =&gt; $img15, 'Img_16' =&gt; $img16, 'Img_17' =&gt; $img17, 'Img_18' =&gt; $img18, 'Img_19' =&gt; $img19, 'Img_20' =&gt; $img20, 'Img_21' =&gt; $img21, 'Img_22' =&gt; $img22, 'Img_23' =&gt; $img23, 'Img_24' =&gt; $img24, 'Img_25' =&gt; $img25, 'Img_26' =&gt; $img26, 'Img_27' =&gt; $img27, 'Img_28' =&gt; $img28, 'Img_29' =&gt; $img29, 'Img_30' =&gt; $img30);
      }
      $stmt-&gt;close();
      return ($row);
  }
  </code></pre>
  
  <p>Then:</p>
  
  <pre><code>$id = $_GET['id'];
  $kitties = checkImages($id);
  if(is_array($kitties)){
      foreach($kitties as $row){
          $total = count(array_filter($row));
      }
  }
  </code></pre>
  
  <p>I'll leave my old question so others can learn from my mistakes. </p>
  
  <h1>Thank you @Alex.</h1>
  
  <p>I'm trying to return the number of rows that are not empty in a sql query. Every time I try, the result is always 1. I've tried to change up a few things but it still seems to be 1.</p>
  
  <p>Edit: I want to count the number of queried rows that are not empty. The rows (Img_#) contain the path and filename of the images.</p>
  
  <p>So for example, id 12 has 20 images stored. For each image stored, the location and filename is stored in one of the img_# fields. So when I query the table, I'd like to check how many of the 30 img_ fields are not empty. </p>
  
  <p>Here's my first try:</p>
  
  <pre><code>function checkImages($id)
  {
      global $mysqli;
      $stmt = $mysqli-&gt;prepare("SELECT
          Img_1,
          Img_2,
          Img_3,
          Img_4,
          Img_5,
          Img_6,
          Img_7,
          Img_8,
          Img_9,
          Img_10,
          Img_11,
          Img_12,
          Img_13,
          Img_14,
          Img_15,
          Img_16,
          Img_17,
          Img_18,
          Img_19,
          Img_20,
          Img_21,
          Img_22,
          Img_23,
          Img_24,
          Img_25,
          Img_26,
          Img_27,
          Img_28,
          Img_29,
          Img_30
          FROM kitties
          WHERE
          id = ?");
      $stmt-&gt;bind_param("i", $id);    
      $stmt-&gt;execute();
      $stmt-&gt;store_result();
      $num_returns = $stmt-&gt;num_rows;
      $stmt-&gt;close();
  
      if ($num_returns &gt; 0)
      {
          return $num_returns;
      }
      else
      {
          return false;   
      }
  }
  </code></pre>
  
  <p>The second version:</p>
  
  <pre><code>function checkImages($id)
  {
      global $mysqli; 
      $stmt = $mysqli-&gt;prepare("SELECT 
          Img_1,
          Img_2,
          Img_3,
          Img_4,
          Img_5,
          Img_6,
          Img_7,
          Img_8,
          Img_9,
          Img_10,
          Img_11,
          Img_12,
          Img_13,
          Img_14,
          Img_15,
          Img_16,
          Img_17,
          Img_18,
          Img_19,
          Img_20,
          Img_21,
          Img_22,
          Img_23,
          Img_24,
          Img_25,
          Img_26,
          Img_27,
          Img_28,
          Img_29,
          Img_30
          FROM kitties
          WHERE
          id = ?");
      $stmt-&gt;bind_param("i", $id);
      $stmt-&gt;execute();
      $stmt-&gt;store_result();
      $stmt-&gt;bind_result($img1, $img2, $img3, $img4, $img5, $img6, $img7, $img8, $img9, $img10, $img11, $img12, $img13, $img14, $img15, $img16, $img17, $img18, $img19, $img20, $img21, $img22, $img23, $img24, $img25, $img26, $img27, $img28, $img29, $img30);
      while ($stmt-&gt;fetch()){
          $row[] = array('Img_1' =&gt; $img1, 'Img_2' =&gt; $img2, 'Img_3' =&gt; $img3, 'Img_4' =&gt; $img4, 'Img_5' =&gt; $img5, 'Img_6' =&gt; $img6, 'Img_7' =&gt; $img7, 'Img_8' =&gt; $img8, 'Img_9' =&gt; $img9, 'Img_10' =&gt; $img10, 'Img_11' =&gt; $img11, 'Img_12' =&gt; $img12, 'Img_13' =&gt; $img13, 'Img_14' =&gt; $img14, 'Img_15' =&gt; $img15, 'Img_16' =&gt; $img16, 'Img_17' =&gt; $img17, 'Img_18' =&gt; $img18, 'Img_19' =&gt; $img19, 'Img_20' =&gt; $img20, 'Img_21' =&gt; $img21, 'Img_22' =&gt; $img22, 'Img_23' =&gt; $img23, 'Img_24' =&gt; $img24, 'Img_25' =&gt; $img25, 'Img_26' =&gt; $img26, 'Img_27' =&gt; $img27, 'Img_28' =&gt; $img28, 'Img_29' =&gt; $img29, 'Img_30' =&gt; $img30);
      }
      $num_returns = $stmt-&gt;num_rows;
      $stmt-&gt;close();
      return ($num_returns);
  }
  </code></pre>
  
  <p>Any advice would be greatly appreciated. Thanks.</p>