Ready to get started?Download WordPress


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

  1. greatwitenorth
    Posted 4 years ago #

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

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

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

  2. greatwitenorth
    Posted 4 years 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
    Posted 4 years ago #

    Or get_col

    See wpdb

Topic Closed

This topic has been closed to new replies.

About this Topic