user1684046
user1684046

Reputation: 1939

Wordpress database query not returning results

apologies that this is very basic stuff but would really appreciate some help. I am trying to query a table in my Wordpress database by adding the following to my child theme's functions.php

$myresults = $wpdb->get_results("SELECT id FROM wp_my_table WHERE user_id=1");

I am trying to view the results of the query by adding

<?php
    var_dump($myresults);
?>

to one of the pages on my website, but it just displays 'NULL'. I have checked using phpMyAdmin and wp_my_table definitely exists, and contains entries where user_id=1. Any ideas?

Upvotes: 0

Views: 124

Answers (2)

user1684046
user1684046

Reputation: 1939

Sorry, I missed something obvious - the scope of the $myresults variable didn't extend to the page I was performing the var_dump on!

Upvotes: 0

Ozan Kurt
Ozan Kurt

Reputation: 3867

not get_results!!! query

$wpdb->get_results(...

to

$wpdb->query(...

Upvotes: 1

Related Questions