Title: problem with $wpdb
Last modified: August 19, 2016

---

# problem with $wpdb

 *  [alyda](https://wordpress.org/support/users/alyda/)
 * (@alyda)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/problem-with-wpdb/)
 * Hi, I’m using $wpdb in my theme files, (a custom Thematic child theme), and everything
   is working fine, BUT if i modify a template file (header-extensions.php) located
   in the PARENT theme directory, i can’t seem to connect to the database.
 * code that works fine in a php file located in my CHILD theme folder works, such
   as
 *     ```
       global $wpdb;
       $lightboxes = $wpdb->get_results( "SELECT * FROM wp_usermeta WHERE meta_key = 'lightbox' AND user_id = $user_ID");
       <select>
       <option>--Select from your lightboxes--</option>
           <?php
   
       	foreach ($lightboxes as $lightbox) {
       		if ($lightbox->meta_value != $editLB) {
       			echo '<option>'.$lightbox->meta_value.'</option>';
       		}
       	}
   
       	?></select>
       ```
   
 * but, the following code, while it seems to connect to the database, returns no
   results
 *     ```
       <?php
       						global $wpdb;
   
       						if ($user_ID) {
       							$getLightboxes = $wpdb->get_results( "SELECT * FROM wp_usermeta WHERE meta_key = 'lightbox' AND user_id = $user_ID");
       						}
   
       						if (!$getLightboxes) {
       							echo '<li><a href="http://therapytest.com/wordpress/?page_id=40">You have no lightboxes</a></li>';
   
       						} else {
       							foreach ($getLightboxes as $lightbox) {
       								echo '<li><a href="">'.$lightbox->meta_value.'</a>
       								<ul><li><a href="">view</a></li></ul>
       								</li>';
       							}
       						}
       						 ?>
       ```
   
 * is there any reason why i am unable to connect to the database and/or return 
   results from the files located in a PARENT theme folder?

Viewing 1 replies (of 1 total)

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/problem-with-wpdb/#post-1362558)
 * Just a guess that it is this causing the problem:
 *     ```
       if ($user_ID) {
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘problem with $wpdb’ is closed to new replies.

## Tags

 * [child them](https://wordpress.org/support/topic-tag/child-them/)
 * [database](https://wordpress.org/support/topic-tag/database/)
 * [no results](https://wordpress.org/support/topic-tag/no-results/)
 * [parent theme](https://wordpress.org/support/topic-tag/parent-theme/)
 * [thematic](https://wordpress.org/support/topic-tag/thematic/)
 * [wpdb](https://wordpress.org/support/topic-tag/wpdb/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [MichaelH](https://wordpress.org/support/users/michaelh/)
 * Last activity: [16 years, 4 months ago](https://wordpress.org/support/topic/problem-with-wpdb/#post-1362558)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
