Title: Issue while fetching data from wordpress database custom table
Last modified: August 19, 2016

---

# Issue while fetching data from wordpress database custom table

 *  Resolved [annujames](https://wordpress.org/support/users/annujames/)
 * (@annujames)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/issue-while-fetching-data-from-wordpress-database-custom-table/)
 * Hi,
 * I am new with the wordpress. I do have some knowledge about php and mysql. I 
   am trying to create a simple custom function using custom table in wordpress 
   database. Its a very simple function. I am creating custom function in function.
   php. It is giving me output However I am unable to figure it out why it is giving
   only single record in output. It might be due to array, but I am week in using
   array in php.
 * Description about function: I have created one table in wordpress database and
   trying to retrieve number of records from that table (more than one record).
 * Here is the function I created.
 * function my_posts()
    { global $wpdb;
 * $checkpost = $wpdb->get_row(“SELECT record_content FROM wp_my_posts WHERE my_ID
   = ’15′”);
 * foreach($checkpost as $mypost_content)
    echo $mypost_content;
 * }
 * Here my_ID is not unique it has multiple records and I want to show those multiple
   records as a output of a query. Currently is showing up only first record in 
   the output.
 * Can any one help me out here.

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

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/issue-while-fetching-data-from-wordpress-database-custom-table/#post-1022071)
 * What about using `get_results` instead of `get_row`?
 * See [wpdb](http://codex.wordpress.org/wpdb)
 *  Thread Starter [annujames](https://wordpress.org/support/users/annujames/)
 * (@annujames)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/issue-while-fetching-data-from-wordpress-database-custom-table/#post-1022134)
 * I used get_results aswell, however, in output it is showing up the same single
   result, where as the output is 3 records. If you see following code the result
   for post_count is coming up 3 but for mypost it showing up single record, how
   do I print all the 3 results?
 * function my_posts()
    { global $wpdb; $checkpost = $wpdb->get_results(“SELECT 
   record_content as mypost, COUNT( record_id ) as post_count FROM `wp_my_posts`
   WHERE my_ID =’15′” );
 * foreach($checkpost as $checkposts)
    {echo $checkposts->post_count; echo $checkposts-
   >mypost; } }
 *  Thread Starter [annujames](https://wordpress.org/support/users/annujames/)
 * (@annujames)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/issue-while-fetching-data-from-wordpress-database-custom-table/#post-1022137)
 * Hi Michael,
 * Thanks for guiding me to the rite direction, I went to wpdb page and found a 
   solution. It has explaned everything.
 * Thanks,
    James

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

The topic ‘Issue while fetching data from wordpress database custom table’ is closed
to new replies.

## Tags

 * [custom function](https://wordpress.org/support/topic-tag/custom-function/)
 * [sql-query](https://wordpress.org/support/topic-tag/sql-query/)

 * 3 replies
 * 2 participants
 * Last reply from: [annujames](https://wordpress.org/support/users/annujames/)
 * Last activity: [17 years, 2 months ago](https://wordpress.org/support/topic/issue-while-fetching-data-from-wordpress-database-custom-table/#post-1022137)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
