最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

database - Help with $wpdb on custom code

programmeradmin1浏览0评论

So i'm trying to implement some custom doing a SELECT to a table i created.

I'm using the following:

global $wpdb;
$fivesdrafts = $wpdb->get_results("SELECT * FROM wpjk_vuln WHERE IDuser = " . um_profile_id());

foreach ( $fivesdrafts as $fivesdraft ) 
{
  echo $fivesdraft->IDprogram;
}

When i open the page where the IDprogram should be displayed it isn't, not sure why.

BUT, if i add an echo with the query, bellow the code:

global $wpdb;

echo "SELECT * FROM wpjk_vuln WHERE IDuser = " . um_profile_id();

$fivesdrafts = $wpdb->get_results("SELECT * FROM wpjk_vuln WHERE IDuser = " . um_profile_id());

foreach ( $fivesdrafts as $fivesdraft ) 
{
  echo $fivesdraft->IDprogram;
}

The page will display the IDprogram, it's just strange. I already hardcoded the um_profile_id() value and it happens the same thing.

So i'm trying to implement some custom doing a SELECT to a table i created.

I'm using the following:

global $wpdb;
$fivesdrafts = $wpdb->get_results("SELECT * FROM wpjk_vuln WHERE IDuser = " . um_profile_id());

foreach ( $fivesdrafts as $fivesdraft ) 
{
  echo $fivesdraft->IDprogram;
}

When i open the page where the IDprogram should be displayed it isn't, not sure why.

BUT, if i add an echo with the query, bellow the code:

global $wpdb;

echo "SELECT * FROM wpjk_vuln WHERE IDuser = " . um_profile_id();

$fivesdrafts = $wpdb->get_results("SELECT * FROM wpjk_vuln WHERE IDuser = " . um_profile_id());

foreach ( $fivesdrafts as $fivesdraft ) 
{
  echo $fivesdraft->IDprogram;
}

The page will display the IDprogram, it's just strange. I already hardcoded the um_profile_id() value and it happens the same thing.

Share Improve this question asked Jun 18, 2020 at 18:58 José CorreiaJosé Correia 1 1
  • Can you echo anything else from within the foreach to make sure the code is executing up to that point? – SeventhSteel Commented Jun 18, 2020 at 21:41
Add a comment  | 

1 Answer 1

Reset to default 0

If the IDuser field is an integer, try:

$um_profile_id = um_profile_id();

$fivesdrafts = $wpdb->get_results("SELECT * FROM wpjk_vuln WHERE IDuser = $um_profile_id");
发布评论

评论列表(0)

  1. 暂无评论