title: PHP MYSQL database class - get mysql_fetch_assoc method to move to next record
body: <p>I'm building a custom database class for use with my projects.  I've built a fetchAssoc() method, however when I call it within a while loop, it's not moving to the next record.  It calls the first record over and over until the script times out.<br>
  Below is the relevant code:</p>
  
  <p>METHODS:</p>
  
  <pre><code>function runQuery($q)
  {
      $this-&gt;numQueries++;
      $this-&gt;query = ($q);
      $this-&gt;setResult($q);
      $this-&gt;result;  
  }
  
  function fetchAssoc($q = NULL)
  {
      if($q == NULL)
      {
          $q = $this-&gt;query;  
      }
      $this-&gt;setResult($q);
      if($q == NULL  || mysql_num_rows($this-&gt;result) &lt; 1)
      {
          return NULL;    
      }
      else 
      {
          return mysql_fetch_assoc($this-&gt;result);
      }
  }
      function setResult($q = NULL)
  {
      if($q == NULL)
      {
          $q = $this-&gt;query;  
      }
      if($q == NULL)
      {
          return FALSE;   
      }
      else
      {
          $this-&gt;result = @mysql_query($q);   
      }
  }
  </code></pre>
  
  <p>SCRIPT:</p>
  
  <pre><code>//runQuery -- Should run the query and store the Result and Query
  $q = "SELECT * FROM make ORDER BY make";
  $db-&gt;runQuery($q);
  
  //fetchAssoc --  return current row of result set and move pointer ahead
  foreach($db-&gt;fetchAssoc() as $key =&gt; $value)
  {
  echo $value." has a foreign key of: ".$key."&lt;br /&gt;";    
  }
  //Also tried
  while($row = fetchAssoc())
  {
      echo $value." has a foreign key of: ".$key."&lt;br /&gt;";    
  }
  </code></pre>