WordPress.org

Ready to get started?Download WordPress

Forums

Using $wpdb in plugin - how to show results in page? (1 post)

  1. pjakubic
    Member
    Posted 1 year ago #

    I am trying to work with data that is in a table, and extract it into my wordpress page.

    What I have done is to create a table called 'wp_axleaa' in my wordpress database. I am trying to query this table and the only result I get printed is “Array”

    I wrote a plugin as follows:

    <?php
    /**
     * @package Trying to Connect
     * @version 1.6
     */
    /*
    Plugin Name: Trying to Connect
    Plugin URI:
    Description: Connecting to DB with $wpdb
    Author: Paul J
    Version: 1.0
    Author URI:
    */
    
    function tc_info() {
    
    global $display;
    global $wpdb;
    
    $display = $wpdb->get_results(
    	'
    	SELECT *
    	FROM $wpdb->wp_axleaa
    	');
    
    print $display;
    
    }
    add_shortcode('showinfo','tc_info');
    
    ?>

    Then I put the shortcode [showinfo] into my wordpress site, and when I view the page then it just shows “Array”. If I add a WHERE clause to the SQL statement, then I get an error message on the page.

    I am very new to wordpress and writing php and would really appreciate any help.

    Thanks very much,

Topic Closed

This topic has been closed to new replies.

About this Topic