Title: Agent047's Replies | WordPress.org

---

# Agent047

  [  ](https://wordpress.org/support/users/agent047/)

 *   [Profile](https://wordpress.org/support/users/agent047/)
 *   [Topics Started](https://wordpress.org/support/users/agent047/topics/)
 *   [Replies Created](https://wordpress.org/support/users/agent047/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/agent047/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/agent047/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/agent047/engagements/)
 *   [Favorites](https://wordpress.org/support/users/agent047/favorites/)

 Search replies:

## Forum Replies Created

Viewing 1 replies (of 1 total)

 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Display mysql table data in a wp page](https://wordpress.org/support/topic/display-mysql-table-data-in-a-wp-page/)
 *  Thread Starter [Agent047](https://wordpress.org/support/users/agent047/)
 * (@agent047)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/display-mysql-table-data-in-a-wp-page/#post-2454454)
 * Hello vtxyzzy,
    Thanks for your reply.Guess what, i got it solved! No need to
   hire anyone ;-).
 * I can explain my solution here for the newbies who end up in this post, geeks,
   please pardon me if this was simple stuff for you… but then iam no geek… just
   a newbie.
 * My aim was to display data from a mysql table onto a wordpress page. I could 
   do it using wpdb class as mentioned in the codex.But i didn’t know the file where
   i should write this php code that contains wpdb class functions to retrieve data
   from mysql table.
 * Hence i installed [Exec-PHP](http://wordpress.org/extend/plugins/exec-php/) plugin.(
   The Exec-PHP plugin executes PHP code in posts, pages and text widgets)
 * Now you are free to write your php code in the page editor and get the retrieved
   data on your page.
 * Steps to retrive data and display it on a wordpress page:
    Create a table in 
   mysql database(assumed that you create a table in the wordpress database itself.)
   In my case database_name: test, table_name:it_testtable contains 2 columns: id(
   number(3)) and name(varchar). In wordpress, create a page and in the visual editor
   write the code(make sure you read the documentation of Exec-PHP plugin and do
   the required configuration mentioned,you will have to ‘disable the visual editor
   while writing’ option under Users section):
 * Here is the code to retrieve data from it_testtable and display it on this page.(
   wpdb class is used for wordpress database,hence you need not mention the connection
   parameters as wpdb already has it configured to the ‘test’ database with the 
   username and password):
 *     ```
       <?php
   
       global $wpdb;
       /* wpdb class should not be called directly.global $wpdb variable is an instantiation of the class already set up to talk to the WordPress database */ 
   
       $result = $wpdb->get_results( "SELECT * FROM it_testtable "); /*mulitple row results can be pulled from the database with get_results function and outputs an object which is stored in $result */
   
       //echo "<pre>"; print_r($result); echo "</pre>";
       /* If you require you may print and view the contents of $result object */
   
       echo "ID"."  "."Name"."<br><br>";
       foreach($result as $row)
        {
   
        echo $row->id."  ".$row->name."<br>";
   
        }
        /* Print the contents of $result looping through each row returned in the result */
   
       ?>
       ```
   
 * Click on update button of the page created. Now you should view the created page
   in your website displaying the required table data.The data may not be displayed
   in a formatted manner.You may use html tables or other plugins to do the same.
   Hope this helps someone.

Viewing 1 replies (of 1 total)