2013-07-29 43 views
0

我想顯示Appnames和的AppId列基於登錄的當前用戶。錯誤使用get_resutls在WordPress定製表

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; 
} 

任何想法,我在做什麼錯在這裏?

+0

是正確的把',ARRAY_A'查詢內串?不應該說,它是get_results的第二個參數? – steven

回答

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']; 
} 

OR

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

WPDB Docs