Title: Retrieving data from a database
Last modified: August 21, 2016

---

# Retrieving data from a database

 *  [Bultack](https://wordpress.org/support/users/bultack/)
 * (@bultack)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/retrieving-data-from-a-database/)
 * Hello!
 * I’m trying to retrieve data from a table in the database, looking in the codex
   I saw that I must use ezSQL and use $wpdb->get_results(‘query’);
 * The problem I have, it’s that I need to show the data from the table in a XxY
   html table.
 * I tried using ASSOC_N to use the numeric Array but I don’t know how to show the
   data correctly, if someone can help me with that problem I will thank

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * (@catacaustic)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/retrieving-data-from-a-database/#post-3672563)
 * Using the `$wpdb` class it’s easy to loop through the results.
 *     ```
       $result = $wpdb->query ('SELECT * FROM tablename');
   
       foreach ($result as $row) {
           echo "<p>".$row->column_name."</p>";
       }
       ```
   
 * Personally I don’t like using numeric arrays for database queries like this because
   they can be very easily messed up. If osmeone adds a column into the database
   table, or adds another column into your query, the index that you use will be
   wrong. It’s always a lot safer to use the assocuative indexing or the object 
   that is returned natively.
 *  Thread Starter [Bultack](https://wordpress.org/support/users/bultack/)
 * (@bultack)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/retrieving-data-from-a-database/#post-3672597)
 * And how I can show the data that I retrieve from my table and put them in a html
   table with a 3×3 format or XxY format?
 *  [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * (@catacaustic)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/retrieving-data-from-a-database/#post-3672599)
 * Just add the HTML code for each row into the `foreach()` loop.
 *     ```
       foreach ($result as $row) {
           echo "<tr>";
           echo "  <td>".$row->col1."</td>";
           echo "  <td>".$row->col2."</td>";
           echo "  <td>".$row->col3."</td>";
           echo "</tr>";
       }
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Retrieving data from a database’ is closed to new replies.

## Tags

 * [database](https://wordpress.org/support/topic-tag/database/)
 * [retrieve data](https://wordpress.org/support/topic-tag/retrieve-data/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * Last activity: [13 years, 1 month ago](https://wordpress.org/support/topic/retrieving-data-from-a-database/#post-3672599)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
