I have had a google about and found a few posts but not a full answer. I want to run my own query when a page is loaded into WordPress. I want to run this query from functions.php:
function performSelect() {
global $wpdb;
$result = $wpdb->query("SELECT ip_address FROM MyTABLE ORDER BY datetime DESC LIMIT 0,1");
print_r( $result);
}
I get a '1' outputting on my page. How do I go about getting ip_address back as an actual field? I have ran the query on the server and it does return an IP, not a 1 as in WordPress!
UPDATE 1
I have now have this working, but I'd like to put in a loop for queries that return more than one row:
$result = $wpdb->get_row("SELECT ip_address FROM MyTABLE ORDER BY datetime DESC LIMIT 0,1", ARRAY_A);
echo $result['ip_address']; // WORKS
How would I go about looping through $result? I've tried a few methods and all error.