0

I am making a custom counter as a wordpress plugin and I hav a little problem with $wpdb This is the query that fails:

private function getMedlemmerfromDB(){
    global $wpdb, $table_prefix;
    $wpdb->plugin_medlemsteller = $table_prefix . "plugin_medlemsteller";
    $fromdb=$wpdb->get_var("SELECT medlemmer FROM $wpdb->plugin_medlemsteller WHERE mID=(SELECT MAX(mID) FROM $wpdb->plugin_medlemsteller)");
    return $fromdb;
}

i do not know what $table_prefix is set to. just hoping it's empty.

in my widget function:

public function widget( $args, $instance ) {
        $medlemmer=getMedlemmerfromDB();
             ...

This fails, and the plugin (witch is still active) doesn't show.

The query works fine, but when I implement it in my plugin it causes the widget to crash.

Hope some one can help me out.

-Krister

2 Answers 2

2

You can try to replace

$medlemmer=getMedlemmerfromDB();

with

$medlemmer=$this->getMedlemmerfromDB();

if widget() and getMedlemmerfromDB() are methods of the same class.

Sign up to request clarification or add additional context in comments.

1 Comment

ok great it worked out for you and good luck with your plugin (it's good karma to vote/accept any helpful answers ;-)
0

You did not define $wpdb->plugin_medlemsteller. Only default WordPress tables can be accessed like that.

You need to define it first:

$wpdb->plugin_medlemsteller = $wpdb->prefix . "plugin_medlemsteller"; 

1 Comment

so if I do it in a function like this: [code] private function getMedlemmerfromDB(){ global $wpdb; $plugin_medlemsteller = $wpdb->prefix . "plugin_medlemsteller"; $fromdb=$wpdb->get_var("SELECT medlemmer FROM $plugin_medlemsteller WHERE mID=(SELECT MAX(mID) FROM plugin_medlemsteller)"); return $fromdb; }[/code]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.