Forums

[resolved] wpdb returns null on pages (3 posts)

  1. greatwitenorth
    Member
    Posted 2 weeks ago #

    I'm trying to access my database through one of my pages and wpdb keeps on returning null. Here's my code:

    <?php
    	global $wpdb;
    	$table_name = $wpdb->prefix . "mcpd_currency";
    	$results = $wpdb->get_var("SELECT code FROM ".$table_name." WHERE currency='Australian Dollars'", ARRAY_A);
    
    var_dump($results);
    ?>

    This works when I use this on my plugin files but not on a page. Does anyone know why this is?

  2. greatwitenorth
    Member
    Posted 2 weeks ago #

    I think I fixed my own problem. For some reason I should have been using get_results instead of using get_var. Still don't know enough as to why get_var doesn't work in this case. All I know is get_results works.

  3. MichaelH
    moderator
    Posted 2 weeks ago #

    Or get_col

    See wpdb

Reply

You must log in to post.

About this Topic

Tags