title: how to use getNumRows() in Joomla after a second query
body: <p>I am developing a php script within the Joomla environment which queries the same table / database twice. Each time I need to know whether any matches are found.</p>
  
  <p>It seemed that the best way would be to use the getNumRows(). The Joomla documentation is very specific on its use:</p>
  
  <blockquote>
    <p>Miscellaneous Result Set Methods getNumRows()</p>
    
    <p>getNumRows() will return the number of result rows found by the last
    query and waiting to be read. To get a result from getNumRows() you
    have to run it after the query and before you have retrieved any
    results.</p>
  </blockquote>
  
  <p>I follow this in my script. At the first query there is no problem, but the second query always throws up a warning - most likely because the getNumRows() call for the second time is after the retrieving results from the first query - which does not comply with the Joomla requirement.</p>
  
  <p>Any ideas how to solve? Many thanks!</p>
  
  <p>The part of my script in question reads:</p>
  
  <pre><code>$db = JFactory::getDBO();
  $query = "SELECT * FROM #__art_mobiles WHERE user_agent_header='$ua'";
  $db-&gt;setQuery($query);
  $rowsAG = $db-&gt;getNumRows();
  $replyAG = $db-&gt;loadRow();
  
  if ($rowsAG == 0) {
  
  //if no match check www.handsetdetection.com
  //see https://www.handsetdetection.com/properties/vendormodel for current list of models in database together with headers
  echo "not in local database - try external&lt;br/&gt;";  
  $prod = '';
  
  if ($hd3-&gt;siteDetect()) {
  
      $replyHD = $hd3-&gt;getReply();
  
      $man = $replyHD['hd_specs']['general_vendor'];
      $dev = $replyHD['hd_specs']['general_model'];
      $os = $replyHD['hd_specs']['general_platform'];
      echo "found in handsetdetection.com database&lt;br/&gt;";
  
      //check for provisional match in local database
      $query = "SELECT * FROM #__art_mobiles WHERE manufacturer='$man' AND device='$dev'";
      $db-&gt;setQuery($query);
      $rowsAGprov = $db-&gt;getNumRows();
      $replyAGprov = $db-&gt;loadRow();
  
      if ($rowsAGprov == 0) { **[ETC]**
  </code></pre>