• I’m just trying to toy around with this global variable to see how it works. I placed this piece of code in my header.php file

    <?php
    
    	global $wpdb;
    
    	$mylink = $wpdb->get_row("SELECT * FROM $wpdb->wp_bb_forums WHERE forum_id = 3", ARRAY_N);
    
    	echo $mylink[0];
    
    ?>

    I’m not getting anything from it. What am I doing wrong?

Viewing 2 replies - 1 through 2 (of 2 total)
  • There might be other issues, but for one, you don’t need the prefix wp_ before your table name, because using $wpdb-> does that for you.

    global $wpdb;
    
    	$mylink = $wpdb->get_row("SELECT * FROM $wpdb->bb_forums WHERE forum_id = 3", ARRAY_N);
    
    	echo $mylink[0];

    I think something like this would work for you.

    <?php
    
    	global $wpdb;
            $table_name = $wpdb->prefix."bb_forums";
    	$mylink = $wpdb->get_row("SELECT * FROM $table_name WHERE forum_id = 3", ARRAY_N);
    
    	print_r($my_link);
    
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Having Issue With $wpdb Class’ is closed to new replies.