title: Is it best to make fewer calls to the database and output the results in an array?
body: <p>I'm trying to create a more succinct way to make hundreds of db calls.  Instead of writing the whole query out every time I wanted to output a single field, I tried to port the code into a class that did all the query work. This is the class I have so far:</p>
  
  <pre><code>class Listing {
  
  /* Connect to the database */
  private $mysql;
  
  function __construct() {
      $this-&gt;mysql = new mysqli(DB_LOC, DB_USER, DB_PASS, DB) or die('Could not connect');
  }
  function getListingInfo($l_id = "", $category = "", $subcategory = "", $username = "", $status = "active") {
      $condition = "`status` = '$status'";
      if (!empty($l_id)) $condition .= "AND `L_ID` = '$l_id'";
      if (!empty($category)) $condition .= "AND `category` = '$category'";
      if (!empty($subcategory)) $condition .= "AND `subcategory` = '$subcategory'";
      if (!empty($username)) $condition .= "AND `username` = '$username'";
      $result = $this-&gt;mysql-&gt;query("SELECT * FROM listing WHERE $condition") or die('Error fetching values');
      $info = $result-&gt;fetch_object() or die('Could not create object');
      return $info;
  }
  }
  </code></pre>
  
  <p>This makes it easy to access any info I want from a single row.</p>
  
  <pre><code>$listing = new Listing;
  echo $listing-&gt;getListingInfo('','Books')-&gt;title;
  </code></pre>
  
  <p>This outputs the title of the first listing in the category "Books".  But if I want to output the price of that listing, I have to make another call to getListingInfo().  This makes another query on the db and again returns only the first row.</p>
  
  <p>This is much more succinct than writing the entire query each time, but I feel like I may be calling the db too often.  Is there a better way to output the data from my class and still be succinct in accessing it (maybe outputting all the rows to an array and returning the array)?  If yes, How?</p>