title: Using MySQLI how can I display data from my database on my website
body: <p>I have long procrastinated switching to MySQLI from MySQL. I have started a new project and decided I'd rather go ahead and start it off with good habits instead of bad ones with deprecated MySQL. </p>
  
  <p>I am trying to figure out how to iterate through a table in my database and display that data on my website. The process, I am sure, is straight forward but the explanation so you will understand the question is less so. I will try to be brief. </p>
  
  <p>Example: I have a database named DATABASE that contains a table called TABLE. On my website I have 5 categories. Each category has a list of 5 items each. Each item in each list in turn has 5 values assigned to it. IE: name, dob, year, month, date. Those 5 values I have stored in my database for each list item in each category.</p>
  
  <p>Visual Representation: <a href="http://imgur.com/PMmbOV6" rel="nofollow">http://imgur.com/PMmbOV6</a> (Each one of the list items has 5 values )</p>
  
  <p>Code: [COLUMN_#] represents the column in the db table corresponding to the value I'd like to pull and insert into the page/html</p>
  
  <pre><code>&lt;div class="category_1"&gt; &lt;!-- First loop iteration --&gt;
      &lt;div class="item_1"&gt; 
          &lt;a title="[COLUMN_1]" href="[COLUMN_2]"&gt;[COLUMN_3]&lt;/a&gt;
          &lt;span class="class"&gt;[COLUMN_4]&lt;/span&gt;
          &lt;span class="class"&gt; [COLUMN_5]&lt;/span&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div class="category_1"&gt; &lt;!-- Second loop iteration --&gt;
      &lt;div class="item_2"&gt; 
          &lt;a title="[COLUMN_1]" href="[COLUMN_2]"&gt;[COLUMN_3]&lt;/a&gt;
          &lt;span class="class"&gt;[COLUMN_4]&lt;/span&gt;
          &lt;span class="class"&gt; [COLUMN_5]&lt;/span&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div class="category_1"&gt; &lt;!-- Third loop iteration --&gt;
      &lt;div class="item_3"&gt; 
          &lt;a title="[COLUMN_1]" href="[COLUMN_2]"&gt;[COLUMN_3]&lt;/a&gt;
          &lt;span class="class"&gt;[COLUMN_4]&lt;/span&gt;
          &lt;span class="class"&gt; [COLUMN_5]&lt;/span&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And so on to the 5th loop iteration for category 1. (one iteration for each list item.)</p>
  
  <p>All the values for all list items from all 5 categories are in the same database so I assume if I wanted to pull the values into the page from the db for category 1 the code would need to be something like - select all from table where category is equal to 1 - I write a loop. Then when the loop finds no more list items with category equal to 1 it ends and moves on to the next script below that to query list items for category 2. And so on.</p>
  
  <p>PHP Code so far: </p>
  
  <pre><code>&lt;?php
  // Connect to and select a database
  $db = new mysqli('localhost', 'root', '', 'DATABASE');
  
  if($db-&gt;connect_errno &gt; 0){
      die('Unable to connect to database [' . $db-&gt;connect_error . ']');
  }
  
  // Query the table 'TABLES' (I'm also assuming I only need to query just the table from here)
  $sql = &lt;&lt;&lt;SQL
      SELECT *
      FROM `TABLE`
  SQL;
  
  if(!$result = $db-&gt;query($sql)){
      die('There was an error running the query [' . $db-&gt;error . ']');
  }
  ?&gt;
  </code></pre>
  
  <p>Thanks in advance this problem is really getting me and I don't want to go back to MySQL. Everyone here tells me not to! =)</p>