title: PHP & MYSQL script inside wordpress theme-functions.php to pull & echo data
body: <p>I have this code in a theme-functions.php file on wordpress, I'm using this script and when needed I'm running a <code>echo</code>followed by the string to replicate the data.</p>
  
  <p>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.</p>
  
  <pre><code>function calliod() {
      global $wpdb;
  
  $user = new WP_User(get_current_user_id());
  $userlogin = $user-&gt;user_login;
  echo $userlogin;
  
  $iodoutput = "SELECT * FROM $wpdb-&gt;iod WHERE wp_iod.USERID ='". $userlogin. "'";
  $result1 = $iodoutput;
  
  if ($result1-&gt;num_rows &gt; 0) {
  
  while($row = $result1-&gt;fetch_assoc()) {
  
  $USERID= "" . $row["USERID"]. "";
  $CurrentPayment= "" . $row["CurrentPayment"]. "";
  $LastMonthPayment= "" . $row["LastMonthPayment"]. "";
  }
  } else {
  echo "0 results";
  }
  }
  </code></pre>
  
  <hr>
  
  <p>RESOLVED:</p>
  
  <p>Here is the code</p>
  
  <p>Inside Functions.php</p>
  
  <pre><code>function calliod(){
  
  global $wpdb;
  $user = new WP_User(get_current_user_id());
  $userlogin = $user-&gt;user_login;
  
  foreach( $wpdb-&gt;get_results("SELECT * FROM wp_iod WHERE wp_iod.USERID ='". $userlogin. "'") as $key =&gt; $row) {
  
  global $USERID;
  $USERID = $row-&gt;USERID;
  }
  }
  </code></pre>
  
  <p>On WP Page</p>
  
  <pre><code>&lt;?php 
  calliod(); 
  echo $GLOBALS['USERID']
  ; ?&gt;
  </code></pre>
  
  <p>Now i can pull any column from the table mentioned as long as i define it in the first script.</p>