title: How to count numbers of row of sql query in joomla and display it?
body: <p>My sql query is this one:</p>
  
  <pre><code>SELECT COUNT(*) AS NumberOfOrders FROM table_products where published = 1;
  </code></pre>
  
  <p>Joomla use Jdatabase to play with tables. I found this on internet:</p>
  
  <pre><code>$db = JFactory::getDbo(); 
   $query = $db-&gt;getQuery(true); 
   $query-&gt;select(array('name', 'email', 'username')) 
     -&gt;from($db-&gt;quoteName('#__my_users')) 
     -&gt;where($db-&gt;quoteName('name') . ' LIKE '. $db-&gt;quote('\'%SMITH%\'')); 
   $db-&gt;setQuery($query); 
  
   // get the count 
   $my_count = $db-&gt;getNumRows(); 
  
   // retrieve the data 
   $rows = $db-&gt;loadObjectList(); 
  
   echo $my_count; 
  </code></pre>
  
  <p>So I try to modify this example for my query:</p>
  
  <pre><code>$db = JFactory::getDbo(); 
   $query = $db-&gt;getQuery(true); 
   $query-&gt;select(array('id')) 
     -&gt;from($db-&gt;quoteName('#__table_products')) 
     -&gt;where($db-&gt;quoteName('published') . ' LIKE '. $db-&gt;quote('1')); 
  
   $db-&gt;setQuery($query); 
  
   // get the count 
   $my_count = $db-&gt;getNumRows(); 
  
   // retrieve the data 
   $rows = $db-&gt;loadObjectList(); 
  </code></pre>
  
  
  
  <p>But it doesn't work. I get empty result. What is wrong?</p>
  
  <p>Someone can help me please?</p>
  
  <p>Regards</p>