querying data via $wpdb and get_row

Question

I am using the Contact Form 7 Plugin to keep data of a form and I would like to query a table to show the results in a template. So this is what my query is:

global $wpdb;

$query = "SELECT count(*) as num 
            FROM wp_cf7dbplugin_submits a,wp_cf7dbplugin_submits b
            WHERE a.field_name = 'Buyer'
                AND a.field_value = 1 
                AND a.submit_time = b.submit_time 
                AND b.field_name = carbrand
                AND b.field_value='Mercedes'";

$results = $wpdb->get_row( $query, OBJECT );
var_dump( $results );

For some reason var_dump() spits out a NULL value. When i run the same query in mysql console I see the result that it is supposed to return 2.

Can anyone advise me on what I’m doing wrong? I went over The Codex to integrate $wpdb variable but I can’t say I was successful…

0
, Mr.T 7 years 2016-08-23T11:12:58-05:00 0 Answers 75 views 0

Leave an answer

Browse
Browse