title: Select a table and display its data in a table using a while loop
body: <p>I am trying to display 25 rows of data from my db.table in an html table using a php while loop to loop for 25 rows. Currently I do not have the 25 rows limiter just wanting to get data displayed at the moment. Here is what I have.</p>
  
  <pre><code>&lt;table&gt;
      &lt;td&gt;&lt;strong&gt;User Name&lt;/strong&gt;&lt;/td&gt;                 
      &lt;td&gt;&lt;strong&gt;User Email&lt;/strong&gt;&lt;/td&gt;                        
      &lt;td&gt;&lt;strong&gt;Is User an Admin&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;Is User Active&lt;/strong&gt;&lt;/td&gt;
  &lt;?php
  $sql = 'SELECT name, login, is_admin, active
          FROM db.users';
  $result = db_exec_prepared_stmt($sql);
  while($rows = mysql_fetch_assoc($result)) {
      $user_name = $rows['name'];
      $user_email = $rows['login'];
      $user_admin = $rows['is_admin'];
      $user_active = $rows['active'];
  
      echo '&lt;tr&gt;
               &lt;td&gt;' . $user_name . '&lt;/td&gt;
               &lt;td&gt;' . $user_email . '&lt;/td&gt;
               &lt;td&gt;' . $user_admin . '&lt;/td&gt;
               &lt;td&gt;' . $user_active . '&lt;/td&gt;
           &lt;/tr&gt;';
  }
  ?&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p><strong>I know that mysql_fetch_assoc() will not work here but I am needing help to get functioning code.</strong> </p>
  
  <p>Here is the db_exec_prepared_stmt() function.</p>
  
  <pre><code>function db_exec_prepared_stmt($sql, $params=array(), $query_type='select') {
  $types = '';
  foreach($params as $p)  {
      if( is_numeric($p)
          &amp;&amp; ($p &lt;= 2147483647) 
          &amp;&amp; (numberOfDecimals($p) === 0)
      ) $types .= 'i';
      else $types .= 's';
  }
  $db = db_open_connection();
  
  if($stmt = $db-&gt;prepare($sql))  { 
      if($types != '')    {
          $binds = array_merge( array($types), $params );
  
  
          call_user_func_array( array($stmt, 'bind_param'), makeValuesReferenced($binds) );
      }
  
      switch($query_type) {
          case 'select':
              $results = db_fetch_assoc($stmt);
              break;
  
          case 'insert':
              $stmt-&gt;execute();
              $results = $db-&gt;insert_id;
              break;
  
          default:
              $stmt-&gt;execute();
              $results = null;
              break;
      }
  
      if('' != $stmt-&gt;error) printf("Error %s: %s.\n", $stmt-&gt;errno, $stmt-&gt;error);
  }
  else    {
      printf("Error %s: %s.\n", $db-&gt;errno, $db-&gt;error);
      $results = null;
  }
  
  db_close_connection($db);
  
  return $results;
  }
  </code></pre>