user1419634 user1419634 - 1 year ago 54
MySQL Question

PHP & MYSQL script inside wordpress theme-functions.php to pull & echo data - RESOLVED

i have this code in a theme-functions.php file on wordpress, im using this script and when needed im running a

followed by the string to replicate the data.

currently when i use this i just get 0 results, echo on the $userlogin is working so i know the filter in the mysql select is fine.

Any ideas where im going wrong?

function calliod() {
global $wpdb;

$user = new WP_User(get_current_user_id());
$userlogin = $user->user_login;
echo $userlogin;

$iodoutput = "SELECT * FROM $wpdb->iod WHERE wp_iod.USERID ='". $userlogin. "'";
$result1 = $iodoutput;

if ($result1->num_rows > 0) {

while($row = $result1->fetch_assoc()) {

$USERID= "" . $row["USERID"]. "";
$CurrentPayment= "" . $row["CurrentPayment"]. "";
$LastMonthPayment= "" . $row["LastMonthPayment"]. "";
} else {
echo "0 results";



Thanks for all the help! here is the code in case anyone else has the same issue

Inside Functions.php

function calliod(){

global $wpdb;
$user = new WP_User(get_current_user_id());
$userlogin = $user->user_login;

foreach( $wpdb->get_results("SELECT * FROM wp_iod WHERE wp_iod.USERID ='". $userlogin. "'") as $key => $row) {

global $USERID;

On WP Page

; ?>

Now i can pull any column from the table mentioned as long as i define it in the first script.


Answer Source

Your query that you're building is never actually executed. See the documentation for the WPDB class, but basically you need a line that says this:

$result1 = $wpdb->get_results( "SELECT * FROM wp_iod WHERE wp_iod.USERID ='". $userlogin. "'" );

More info here:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download