• Hello,

    I’m currently trying to show data from an external database on my wordpress website. I’m not really new to wordpress but this kind of topic is brand new to me, so I’m a little bit lost here.

    So I have a database called “persons” with a table “stats_persons” and I want to grab the “lastconnection” (https://i.imgur.com/FJcGRQR.png) which basically contains the data when the person was last online.

    I have created a child theme and within the functions.php it currently looks like this:

    $wpdb_b = new wpdb(DB_USER, DB_PASS, ‘stats_persons’, ‘external_ip’);
    $wpdb_b->get_results( “SELECT * FROM stats_persons” );

    What would I need to do in order to show “lastconnection” data?

    Thank you very much!

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Place your code in a function declaration so it does not execute until it’s called. Better yet, make it into a shortcode handler so it can be called from page content.
    https://developer.www.ads-software.com/plugins/shortcodes/

    How you display the results depends upon the nature of table structure. To get an idea of what sort of data you are getting back, you could do:
    return print_r( $wpdb_b->get_results('SELECT * FROM stats_persons'), true );
    as the final line in your shortcode handler function declaration.

Viewing 1 replies (of 1 total)
  • The topic ‘Show data from external database’ is closed to new replies.