简体   繁体   中英

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?

not get_results!!! query

$wpdb->get_results(...

to

$wpdb->query(...

抱歉,我错过了一些明显的事情-$ myresults变量的范围未扩展到我正在执行var_dump的页面上!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM