0

我正在尝试根据当前登录的用户显示 Appnames 和 AppId 列。

global $wpdb;
global $current_user;
get_currentuserinfo();

$UserId= $current_user->ID;


$siteAppIds = $wpdb->get_results($wpdb->prepare("SELECT AppID, AppNames FROM       
   app_BasicInfo WHERE WpUserId =$UserId, ARRAY_A") );


foreach ( $siteAppIds as $siteAppId) {

echo  $siteAppId-> AppNames;
}

知道我在这里做错了什么吗?

4

1 回答 1

0

您正在使用ARRAY_A和回显,就像object尝试这样,

$siteAppIds = $wpdb->get_results($wpdb->prepare("SELECT AppID, AppNames FROM       
             app_BasicInfo WHERE WpUserId =$UserId, ARRAY_A") );
foreach ( $siteAppIds as $siteAppId) {
   echo  $siteAppId['AppNames'];
}

或者

$siteAppIds = $wpdb->get_results($wpdb->prepare("SELECT AppID, AppNames FROM       
             app_BasicInfo WHERE WpUserId =$UserId, OBJECT") );
foreach ( $siteAppIds as $siteAppId) {
   echo  $siteAppId->AppNames;
}

阅读WPDB 文档

于 2013-07-29T04:44:28.823 回答